{"id":777,"date":"2024-03-19T14:07:40","date_gmt":"2024-03-19T14:07:40","guid":{"rendered":"https:\/\/www.alexandrewsdesign.co.uk\/wordpress\/?p=777"},"modified":"2024-03-20T13:14:32","modified_gmt":"2024-03-20T13:14:32","slug":"image-processing-script-documentation","status":"publish","type":"post","link":"https:\/\/www.alexandrewsdesign.co.uk\/wordpress\/?p=777","title":{"rendered":"Image Processing Script Documentation"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.alexandrewsdesign.co.uk\/wordpress\/wp-content\/uploads\/2024\/03\/cover.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"150\" src=\"https:\/\/www.alexandrewsdesign.co.uk\/wordpress\/wp-content\/uploads\/2024\/03\/cover.jpg\" alt=\"\" class=\"wp-image-783\" srcset=\"https:\/\/www.alexandrewsdesign.co.uk\/wordpress\/wp-content\/uploads\/2024\/03\/cover.jpg 800w, https:\/\/www.alexandrewsdesign.co.uk\/wordpress\/wp-content\/uploads\/2024\/03\/cover-300x56.jpg 300w, https:\/\/www.alexandrewsdesign.co.uk\/wordpress\/wp-content\/uploads\/2024\/03\/cover-768x144.jpg 768w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Using BAT and Photoshop scripts to automate bulk image processing for e-commerce.<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Objective:<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The purpose of this script is to automate the process of fetching images from a server, organising them into different folders, and then processing them using Photoshop scripts. Specifically, the script performs the following tasks:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Copies images from a specified server location.<\/li>\n\n\n\n<li>Organises the copied images into different folders based on certain criteria.<\/li>\n\n\n\n<li>Runs Photoshop scripts to convert the images to specific dimensions, colour profiles, and file formats.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Components:<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">1. Copying Images:<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">The script begins by setting variables such as copyfrom, folder, and SKUs.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">copyfrom: Specifies the source location from which images will be copied. This is typically a network path (\\\\server2\\graphics\\IMAGES\\HIGH RES RGB).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">folder: Specifies the destination folder where images will be organised.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">SKUs: Specifies a list of image filenames or patterns to be copied. These patterns can include wildcard characters such as *, allowing for the selection of multiple files based on a common pattern.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">2. Image Copy Process:<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">The ROBOCOPY command is used to copy images from the specified source location (%copyfrom%) to the destination folder (D:\\imagepull\\%folder%\\RGB).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\/r:3 \/w:3: Specifies retry and wait times in case of any errors during the copy process.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\/LOG:D:\\%folder%-LOG.txt: Logs the copy process to a text file for reference.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">3. Image Processing:<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">If the copy process is successful (if &#8220;%ERRORLEVEL%&#8221;==&#8221;0&#8221;), the script proceeds to further process the copied images.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It organises the copied images into subfolders for different processing tasks, including:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>1000&#215;1000: Folder for images resized to 1000&#215;1000 pixels.<\/li>\n\n\n\n<li>2000&#215;2000: Folder for images resized to 2000&#215;2000 pixels.<\/li>\n\n\n\n<li>CMYK: Folder for images converted to CMYK colour profile.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The robocopy command is used to copy images from the original RGB folder to the newly created folders (1000&#215;1000, 2000&#215;2000, CMYK) while preserving the directory structure (\/E).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Subsequently, Photoshop scripts (1000&#215;1000.exe, 2000&#215;2000.exe, CMYK.exe, Clip-to-PNG.exe) are executed to perform specific image processing tasks on the images in each folder:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>1000&#215;1000.exe: Resizes images to 1000&#215;1000 pixels.<\/li>\n\n\n\n<li>2000&#215;2000.exe: Resizes images to 2000&#215;2000 pixels.<\/li>\n\n\n\n<li>CMYK.exe: Converts images to CMYK colour profile.<\/li>\n\n\n\n<li>Clip-to-PNG.exe: Converts images to PNG file format.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Each Photoshop script is executed using the start command, specifying the executable path and the folder containing images as arguments.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">4. Error Handling:<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">If the copy process fails, the script prints &#8220;failed&#8221; to the console.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The script pauses execution (Pause) to keep the console window open for review and exits (Exit).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Usage:<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To use this script, replace placeholders such as \\\\server2\\graphics\\IMAGES\\HIGH RES RGB with the appropriate source location and ensure that Photoshop scripts (1000&#215;1000.exe, 2000&#215;2000.exe, CMYK.exe, Clip-to-PNG.exe) exist in the specified locations (C:\\Users\\Public).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Execute the script in a Windows environment to automate the image processing tasks.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Notes:<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Ensure that appropriate permissions are set for accessing the source and destination locations, as well as executing the Photoshop scripts.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Review the log file (%folder%-LOG.txt) for any errors or issues encountered during the image copying process.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Script:<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>@echo off\nset \"copyfrom=\\server2\\graphics\\IMAGES\\HIGH RES RGB\"\nset \"folder=bigtest\"\nset \"SKUs=33011<em>.jpg 9580010<\/em>.jpg 9580007<em>.jpg 9580020<\/em>.jpg 9580021<em>.jpg 9580016<\/em>.jpg 9580017<em>.jpg 9580022<\/em>.jpg 9580023<em>.jpg 9580024<\/em>.jpg GW63320<em>.jpg GW63321<\/em>.jpg GW63322<em>.jpg GW63323<\/em>.jpg 9584241<em>.jpg 9584244<\/em>.jpg 9584245<em>.jpg 9584246<\/em>.jpg 9584247<em>.jpg 9584248<\/em>.jpg POS528<em>.jpg POS529<\/em>.jpg LT173<em>.jpg LT176<\/em>.jpg LT177<em>.jpg LT178<\/em>.jpg SYSDSB*.jpg\"\nROBOCOPY \"%copyfrom%\" \"D:\\imagepull\\%folder%\\RGB\" %SKUs% \/r:3 \/w:3 \/LOG:D:\\%folder%-LOG.txt\n\nrobocopy \"D:\\imagepull\\%folder%\\RGB\" \"D:\\imagepull\\%folder%\\1000x1000\" \/E\nrobocopy \"D:\\imagepull\\%folder%\\RGB\" \"D:\\imagepull\\%folder%\\2000x2000\" \/E\nrobocopy \"D:\\imagepull\\%folder%\\RGB\" \"D:\\imagepull\\%folder%\\CMYK\" \/E\n\nstart \"\" \"C:\\Users\\Public\\1000x1000.exe\" \"D:\\imagepull\\%folder%\\1000x1000\\\"\nstart \"\" \"C:\\Users\\Public\\2000x2000.exe\" \"D:\\imagepull\\%folder%\\2000x2000\\\"\nstart \"\" \"C:\\Users\\Public\\CMYK.exe\" \"D:\\imagepull\\%folder%\\CMYK\\\"\nstart \"\" \"C:\\Users\\Public\\Clip-to-PNG.exe\" \"D:\\imagepull\\%folder%\\rgb\\\"\n\nPause\nExit\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Automating SKU Code Formatting with Google Sheets<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To streamline the process of generating the list of image filenames (SKUs), you can utilise Google Sheets to automate the addition of &#8220;*.jpg&#8221; to product SKU codes. Here&#8217;s how you can set it up:<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">1. Create a Google Sheet:<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Begin by creating a new Google Sheet in Google Drive.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">2. Enter Product SKU Codes:<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">In a column, paste or enter the product SKU codes for which you need to generate the image filenames.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">3. Apply Formula to Append &#8220;*.jpg&#8221;:<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">In an adjacent column, apply a formula to concatenate the SKU codes with &#8220;*.jpg&#8221;.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Assuming SKU codes are in column A, you can use a formula like:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><em>=A1 &amp; \".jpg\"<\/em><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Drag the fill handle of the cell with the formula down to apply it to all SKU codes.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">4. Copy Formatted SKUs:<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Once the formula is applied, the adjacent column will contain the formatted SKUs with &#8220;*.jpg&#8221; appended to each code.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">5. Copy and Paste Formatted SKUs:<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Select the column containing the formatted SKUs and copy them.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Paste the copied SKUs into your batch script (SKUs variable) in place of the manually entered list.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This will dynamically generate the list of image filenames based on the product SKU codes entered in the Google Sheet.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Example:<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">On this sheet I have added some extra functionality. In the first column I paste the SKUs for all the images I require. I can then change the extension in the &#8220;Grab Extension&#8221; cell. In this example I use the wildcard *.jpg. The &#8220;Quick copy cell&#8221; then automatically populates with all of the codes in one line making it easer to add to the BAT. I have also added renaming to this sheet where I can add the new name for each SKU and it will output a ren command. CMD can be run in the image location and this command can be executed by simply pasting the content of the &#8220;CMD code&#8221; column.<br><br>Finally I have added a Check column. Here I paste a list of images that have been copied and I use conditional formatting to show what images I&#8217;m missing from my original list.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.alexandrewsdesign.co.uk\/wordpress\/wp-content\/uploads\/2024\/03\/image.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"381\" src=\"https:\/\/www.alexandrewsdesign.co.uk\/wordpress\/wp-content\/uploads\/2024\/03\/image-1024x381.png\" alt=\"\" class=\"wp-image-781\" srcset=\"https:\/\/www.alexandrewsdesign.co.uk\/wordpress\/wp-content\/uploads\/2024\/03\/image-1024x381.png 1024w, https:\/\/www.alexandrewsdesign.co.uk\/wordpress\/wp-content\/uploads\/2024\/03\/image-300x112.png 300w, https:\/\/www.alexandrewsdesign.co.uk\/wordpress\/wp-content\/uploads\/2024\/03\/image-768x286.png 768w, https:\/\/www.alexandrewsdesign.co.uk\/wordpress\/wp-content\/uploads\/2024\/03\/image-1536x571.png 1536w, https:\/\/www.alexandrewsdesign.co.uk\/wordpress\/wp-content\/uploads\/2024\/03\/image-900x335.png 900w, https:\/\/www.alexandrewsdesign.co.uk\/wordpress\/wp-content\/uploads\/2024\/03\/image.png 1613w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Benefits:<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Using Google Sheets to generate formatted SKUs offers flexibility and efficiency.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It allows for easy modification and updating of SKU lists.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Automating this process reduces the chance of manual errors and saves time when preparing the batch script.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Using BAT and Photoshop scripts to automate bulk image processing for e-commerce. Objective: The purpose of this script is to automate the process of fetching images from a server, organising them into different folders, and then processing them using Photoshop scripts. Specifically, the script performs the following tasks: Components: 1. Copying Images: The script begins\u2026 <a href=\"https:\/\/www.alexandrewsdesign.co.uk\/wordpress\/?p=777\">Read More &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":783,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-777","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-portfolio-slug"],"_links":{"self":[{"href":"https:\/\/www.alexandrewsdesign.co.uk\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/777","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.alexandrewsdesign.co.uk\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.alexandrewsdesign.co.uk\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.alexandrewsdesign.co.uk\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.alexandrewsdesign.co.uk\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=777"}],"version-history":[{"count":9,"href":"https:\/\/www.alexandrewsdesign.co.uk\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/777\/revisions"}],"predecessor-version":[{"id":801,"href":"https:\/\/www.alexandrewsdesign.co.uk\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/777\/revisions\/801"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.alexandrewsdesign.co.uk\/wordpress\/index.php?rest_route=\/wp\/v2\/media\/783"}],"wp:attachment":[{"href":"https:\/\/www.alexandrewsdesign.co.uk\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=777"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.alexandrewsdesign.co.uk\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=777"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.alexandrewsdesign.co.uk\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=777"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}