{"id":694,"date":"2015-06-17T19:09:38","date_gmt":"2015-06-17T16:09:38","guid":{"rendered":"https:\/\/imagga.com\/blog\/?p=694"},"modified":"2019-06-06T16:09:00","modified_gmt":"2019-06-06T13:09:00","slug":"batch-image-processing-from-local-folder-using-imagga-api","status":"publish","type":"post","link":"https:\/\/imagga.com\/blog\/batch-image-processing-from-local-folder-using-imagga-api\/","title":{"rendered":"Batch Image Processing From Local Folder Using Imagga API"},"content":{"rendered":"<p><img class=\"aligncenter size-full wp-image-696\" src=\"https:\/\/imagga.com\/blog\/wp-content\/uploads\/2015\/11\/imagga_code_tips.jpg\" alt=\"Batch Upload of Photos for Image Recognition\" width=\"1200\" height=\"500\" srcset=\"https:\/\/imagga.com\/blog\/wp-content\/uploads\/2015\/11\/imagga_code_tips.jpg 1200w, https:\/\/imagga.com\/blog\/wp-content\/uploads\/2015\/11\/imagga_code_tips-800x333.jpg 800w, https:\/\/imagga.com\/blog\/wp-content\/uploads\/2015\/11\/imagga_code_tips-768x320.jpg 768w, https:\/\/imagga.com\/blog\/wp-content\/uploads\/2015\/11\/imagga_code_tips-1024x427.jpg 1024w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/p>\n<p>This blog post is part of series on How-Tos for those of you who are not quite experienced and need a bit of help to set up and use properly our powerful image recognition APIs.<\/p>\n<p>In this one we will help you to batch process (using our Tagging or Color extraction API) a whole folder of photos, that reside on your local computer. To make that possible we\u2019ve written a short script in the programming language Python:<a href=\"https:\/\/bitbucket.org\/snippets\/imaggateam\/LL6dd\"> https:\/\/bitbucket.org\/snippets\/imaggateam\/LL6dd<\/a><\/p>\n<p>Feel free to reuse or modify it. Here\u2019s a short explanation what it does.\u00a0The script requires the Python package, which you can install using <a href=\"http:\/\/docs.python-requests.org\/en\/latest\/user\/install\/#install\" target=\"_blank\" rel=\"noopener noreferrer\">this guide<\/a>.<\/p>\n<p>It uses requests\u2019 HTTPBasicAuth to initialize a Basic authentication used in Imagga\u2019s API from a given API_KEY and API_SECRET which you have to manually set in the first lines of the script.<\/p>\n<p>There are three main functions in the script &#8211; upload_image, tag_image, extract_colors.<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li><b>upload_image<\/b>(image_path) &#8211; uploads your file to our API using the content endpoint, the argument image_path is the path to the file in your local file system. The function returns the content id associated with the image.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<ul>\n<li><b>tag_image<\/b>(image, content_id=False, verbose=False, language=&#8217;en&#8217;) &#8211; the function tags a given image using Imagga\u2019s Tagging API. You can provide an image url or a content id (from upload_image) to the \u2018image\u2019 argument but you will also have to set content_id=True. By setting the verbose argument to True, the returned tags will also contain their origin (whether it is coming from machine learning recognition or from additional analysis). The last parameter is \u2018language\u2019 if you want your output tags to be translated in one of Imagga\u2019s supported 50 (+1) languages. You can find the supported languages from here &#8211; http:\/\/docs.imagga.com\/#auto-tagging<\/li>\n<\/ul>\n<ul>\n<li><b>extract_colors<\/b>(image, content_id=False) &#8211; using this function you can extract colors from your image using our Color Extraction API. Just like the tag_image function, you can provide an image URL or a content id (by also setting content_id argument to True).<\/li>\n<\/ul>\n<h3><b>Script usage:<\/b><\/h3>\n<p><b>Note: <\/b>You need to install the Python package <b>requests<\/b> in order to use the script. You can find <a href=\"http:\/\/docs.python-requests.org\/en\/latest\/user\/install\/#install\" target=\"_blank\" rel=\"noopener noreferrer\">installation notes here<\/a>.<\/p>\n<p>You have to manually set the API_KEY and API_SECRET variables found in the first lines of the script by replacing YOUR_API_KEY and YOUR_API_SECRET with your API key and secret.<\/p>\n<p><b>Usage (in your terminal or CMD):<\/b><\/p>\n<p><b>python <\/b><a href=\"https:\/\/bitbucket.org\/snippets\/imaggateam\/LL6dd#file-tag_images.py\"><b>tag_images.py<\/b><\/a> <b>&lt;input_folder&gt; &lt;output_folder&gt;<\/b> &#8211;language=<b>&lt;language&gt; <\/b>&#8211;verbose=<b>&lt;verbose&gt;<\/b> &#8211;merged-output=<b>&lt;merged_output&gt;<\/b> &#8211;include-colors=<b>&lt;include_colors&gt;<\/b><\/p>\n<p>The script has two required &#8211; &lt;input_folder&gt;, &lt;output_folder&gt; and four optional arguments &#8211; &lt;language&gt;, &lt;verbose&gt;, &lt;merged_output&gt;, &lt;include_colors&gt;.<\/p>\n<ul>\n<li><b>&lt;input_folder&gt; &#8211; required<\/b>, the input folder containing the images you would like to tag.<\/li>\n<li><b>&lt;output_folder&gt; &#8211; required<\/b>, the output folder where the tagging JSON response will be saved.<\/li>\n<li><b>&lt;language&gt;<\/b> &#8211; <i>optional<\/i>, <i>default: en<\/i>, the output tags will be translated in the given language (a list of supported languages can be found here: <a href=\"http:\/\/docs.imagga.com\/#auto-tagging\">http:\/\/docs.imagga.com\/#auto-tagging<\/a>)<\/li>\n<li><b>&lt;verbose&gt;<\/b> &#8211; <i>optional<\/i>, <i>default: False<\/i>, if True the output tags will contain an origin key (whether it is coming from machine learning recognition or from additional analysis)<\/li>\n<li><b>&lt;include_colors&gt;<\/b> &#8211; <i>optional<\/i>, <i>default: False<\/i>, if True the output will also contain color extraction results for each image.<\/li>\n<li><b>&lt;merged_output&gt;<\/b> &#8211; <i>optional<\/i>, <i>default: False<\/i>, if True the output will be merged in a JSON single file, otherwise &#8211; separate JSON files for each image.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>This blog post is part of series on How-Tos for those of you who are not quite experienced and need [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":2191,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[31,44,82,95],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v17.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Batch Image Processing From Local Folder With Imagga API<\/title>\n<meta name=\"description\" content=\"Script that will help you to batch process (using Tagging or Color extraction API) a whole folder of photos, that reside on your local computer.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/imagga.com\/blog\/batch-image-processing-from-local-folder-using-imagga-api\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Batch Image Processing From Local Folder With Imagga API\" \/>\n<meta property=\"og:description\" content=\"Script that will help you to batch process (using Tagging or Color extraction API) a whole folder of photos, that reside on your local computer.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/imagga.com\/blog\/batch-image-processing-from-local-folder-using-imagga-api\/\" \/>\n<meta property=\"og:site_name\" content=\"Imagga Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/imagga\/\" \/>\n<meta property=\"article:published_time\" content=\"2015-06-17T16:09:38+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-06-06T13:09:00+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/imagga.com\/blog\/wp-content\/uploads\/2015\/11\/Processing_Power.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"1080\" \/>\n<meta name=\"twitter:card\" content=\"summary\" \/>\n<meta name=\"twitter:creator\" content=\"@imagga\" \/>\n<meta name=\"twitter:site\" content=\"@imagga\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Chris Georgiev\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https:\/\/imagga.com\/blog\/#organization\",\"name\":\"Imagga\",\"url\":\"https:\/\/imagga.com\/blog\/\",\"sameAs\":[\"https:\/\/www.facebook.com\/imagga\/\",\"https:\/\/twitter.com\/imagga\",\"https:\/\/www.linkedin.com\/company\/imagga\/\",\"https:\/\/twitter.com\/imagga\"],\"logo\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/imagga.com\/blog\/#logo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/imagga.com\/blog\/wp-content\/uploads\/2017\/04\/logo_white_blog.svg\",\"contentUrl\":\"https:\/\/imagga.com\/blog\/wp-content\/uploads\/2017\/04\/logo_white_blog.svg\",\"width\":\"27\",\"height\":\"29\",\"caption\":\"Imagga\"},\"image\":{\"@id\":\"https:\/\/imagga.com\/blog\/#logo\"}},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/imagga.com\/blog\/#website\",\"url\":\"https:\/\/imagga.com\/blog\/\",\"name\":\"Imagga Blog\",\"description\":\"Image recognition in the cloud\",\"publisher\":{\"@id\":\"https:\/\/imagga.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/imagga.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/imagga.com\/blog\/batch-image-processing-from-local-folder-using-imagga-api\/#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/imagga.com\/blog\/wp-content\/uploads\/2015\/11\/Processing_Power.jpg\",\"contentUrl\":\"https:\/\/imagga.com\/blog\/wp-content\/uploads\/2015\/11\/Processing_Power.jpg\",\"width\":1920,\"height\":1080},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/imagga.com\/blog\/batch-image-processing-from-local-folder-using-imagga-api\/#webpage\",\"url\":\"https:\/\/imagga.com\/blog\/batch-image-processing-from-local-folder-using-imagga-api\/\",\"name\":\"Batch Image Processing From Local Folder With Imagga API\",\"isPartOf\":{\"@id\":\"https:\/\/imagga.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/imagga.com\/blog\/batch-image-processing-from-local-folder-using-imagga-api\/#primaryimage\"},\"datePublished\":\"2015-06-17T16:09:38+00:00\",\"dateModified\":\"2019-06-06T13:09:00+00:00\",\"description\":\"Script that will help you to batch process (using Tagging or Color extraction API) a whole folder of photos, that reside on your local computer.\",\"breadcrumb\":{\"@id\":\"https:\/\/imagga.com\/blog\/batch-image-processing-from-local-folder-using-imagga-api\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/imagga.com\/blog\/batch-image-processing-from-local-folder-using-imagga-api\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/imagga.com\/blog\/batch-image-processing-from-local-folder-using-imagga-api\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/imagga.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Batch Image Processing From Local Folder Using Imagga API\"}]},{\"@type\":\"Article\",\"@id\":\"https:\/\/imagga.com\/blog\/batch-image-processing-from-local-folder-using-imagga-api\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/imagga.com\/blog\/batch-image-processing-from-local-folder-using-imagga-api\/#webpage\"},\"author\":{\"@id\":\"https:\/\/imagga.com\/blog\/#\/schema\/person\/a96fcdcdb1e1683cbca03bce800d848b\"},\"headline\":\"Batch Image Processing From Local Folder Using Imagga API\",\"datePublished\":\"2015-06-17T16:09:38+00:00\",\"dateModified\":\"2019-06-06T13:09:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/imagga.com\/blog\/batch-image-processing-from-local-folder-using-imagga-api\/#webpage\"},\"wordCount\":639,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/imagga.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/imagga.com\/blog\/batch-image-processing-from-local-folder-using-imagga-api\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/imagga.com\/blog\/wp-content\/uploads\/2015\/11\/Processing_Power.jpg\",\"keywords\":[\"image processing\",\"image analysis\",\"image classification\",\"image tagging\"],\"articleSection\":[\"Trending\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/imagga.com\/blog\/batch-image-processing-from-local-folder-using-imagga-api\/#respond\"]}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/imagga.com\/blog\/#\/schema\/person\/a96fcdcdb1e1683cbca03bce800d848b\",\"name\":\"Chris Georgiev\",\"url\":\"https:\/\/imagga.com\/blog\/author\/chris\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Batch Image Processing From Local Folder With Imagga API","description":"Script that will help you to batch process (using Tagging or Color extraction API) a whole folder of photos, that reside on your local computer.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/imagga.com\/blog\/batch-image-processing-from-local-folder-using-imagga-api\/","og_locale":"en_US","og_type":"article","og_title":"Batch Image Processing From Local Folder With Imagga API","og_description":"Script that will help you to batch process (using Tagging or Color extraction API) a whole folder of photos, that reside on your local computer.","og_url":"https:\/\/imagga.com\/blog\/batch-image-processing-from-local-folder-using-imagga-api\/","og_site_name":"Imagga Blog","article_publisher":"https:\/\/www.facebook.com\/imagga\/","article_published_time":"2015-06-17T16:09:38+00:00","article_modified_time":"2019-06-06T13:09:00+00:00","og_image":[{"width":1920,"height":1080,"url":"http:\/\/imagga.com\/blog\/wp-content\/uploads\/2015\/11\/Processing_Power.jpg","type":"image\/jpeg"}],"twitter_card":"summary","twitter_creator":"@imagga","twitter_site":"@imagga","twitter_misc":{"Written by":"Chris Georgiev","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Organization","@id":"https:\/\/imagga.com\/blog\/#organization","name":"Imagga","url":"https:\/\/imagga.com\/blog\/","sameAs":["https:\/\/www.facebook.com\/imagga\/","https:\/\/twitter.com\/imagga","https:\/\/www.linkedin.com\/company\/imagga\/","https:\/\/twitter.com\/imagga"],"logo":{"@type":"ImageObject","@id":"https:\/\/imagga.com\/blog\/#logo","inLanguage":"en-US","url":"https:\/\/imagga.com\/blog\/wp-content\/uploads\/2017\/04\/logo_white_blog.svg","contentUrl":"https:\/\/imagga.com\/blog\/wp-content\/uploads\/2017\/04\/logo_white_blog.svg","width":"27","height":"29","caption":"Imagga"},"image":{"@id":"https:\/\/imagga.com\/blog\/#logo"}},{"@type":"WebSite","@id":"https:\/\/imagga.com\/blog\/#website","url":"https:\/\/imagga.com\/blog\/","name":"Imagga Blog","description":"Image recognition in the cloud","publisher":{"@id":"https:\/\/imagga.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/imagga.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"ImageObject","@id":"https:\/\/imagga.com\/blog\/batch-image-processing-from-local-folder-using-imagga-api\/#primaryimage","inLanguage":"en-US","url":"https:\/\/imagga.com\/blog\/wp-content\/uploads\/2015\/11\/Processing_Power.jpg","contentUrl":"https:\/\/imagga.com\/blog\/wp-content\/uploads\/2015\/11\/Processing_Power.jpg","width":1920,"height":1080},{"@type":"WebPage","@id":"https:\/\/imagga.com\/blog\/batch-image-processing-from-local-folder-using-imagga-api\/#webpage","url":"https:\/\/imagga.com\/blog\/batch-image-processing-from-local-folder-using-imagga-api\/","name":"Batch Image Processing From Local Folder With Imagga API","isPartOf":{"@id":"https:\/\/imagga.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/imagga.com\/blog\/batch-image-processing-from-local-folder-using-imagga-api\/#primaryimage"},"datePublished":"2015-06-17T16:09:38+00:00","dateModified":"2019-06-06T13:09:00+00:00","description":"Script that will help you to batch process (using Tagging or Color extraction API) a whole folder of photos, that reside on your local computer.","breadcrumb":{"@id":"https:\/\/imagga.com\/blog\/batch-image-processing-from-local-folder-using-imagga-api\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/imagga.com\/blog\/batch-image-processing-from-local-folder-using-imagga-api\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/imagga.com\/blog\/batch-image-processing-from-local-folder-using-imagga-api\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/imagga.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Batch Image Processing From Local Folder Using Imagga API"}]},{"@type":"Article","@id":"https:\/\/imagga.com\/blog\/batch-image-processing-from-local-folder-using-imagga-api\/#article","isPartOf":{"@id":"https:\/\/imagga.com\/blog\/batch-image-processing-from-local-folder-using-imagga-api\/#webpage"},"author":{"@id":"https:\/\/imagga.com\/blog\/#\/schema\/person\/a96fcdcdb1e1683cbca03bce800d848b"},"headline":"Batch Image Processing From Local Folder Using Imagga API","datePublished":"2015-06-17T16:09:38+00:00","dateModified":"2019-06-06T13:09:00+00:00","mainEntityOfPage":{"@id":"https:\/\/imagga.com\/blog\/batch-image-processing-from-local-folder-using-imagga-api\/#webpage"},"wordCount":639,"commentCount":0,"publisher":{"@id":"https:\/\/imagga.com\/blog\/#organization"},"image":{"@id":"https:\/\/imagga.com\/blog\/batch-image-processing-from-local-folder-using-imagga-api\/#primaryimage"},"thumbnailUrl":"https:\/\/imagga.com\/blog\/wp-content\/uploads\/2015\/11\/Processing_Power.jpg","keywords":["image processing","image analysis","image classification","image tagging"],"articleSection":["Trending"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/imagga.com\/blog\/batch-image-processing-from-local-folder-using-imagga-api\/#respond"]}]},{"@type":"Person","@id":"https:\/\/imagga.com\/blog\/#\/schema\/person\/a96fcdcdb1e1683cbca03bce800d848b","name":"Chris Georgiev","url":"https:\/\/imagga.com\/blog\/author\/chris\/"}]}},"_links":{"self":[{"href":"https:\/\/imagga.com\/blog\/wp-json\/wp\/v2\/posts\/694"}],"collection":[{"href":"https:\/\/imagga.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/imagga.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/imagga.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/imagga.com\/blog\/wp-json\/wp\/v2\/comments?post=694"}],"version-history":[{"count":9,"href":"https:\/\/imagga.com\/blog\/wp-json\/wp\/v2\/posts\/694\/revisions"}],"predecessor-version":[{"id":3283,"href":"https:\/\/imagga.com\/blog\/wp-json\/wp\/v2\/posts\/694\/revisions\/3283"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/imagga.com\/blog\/wp-json\/wp\/v2\/media\/2191"}],"wp:attachment":[{"href":"https:\/\/imagga.com\/blog\/wp-json\/wp\/v2\/media?parent=694"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/imagga.com\/blog\/wp-json\/wp\/v2\/categories?post=694"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/imagga.com\/blog\/wp-json\/wp\/v2\/tags?post=694"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}