How can I batch-convert product photos to square images without cropping on Windows?

Asked 11/22/2015

5 views

2 answers

0

I have hundreds of product photos in different dimensions, and my ERP only accepts square (1:1) images. I do not want to crop the photos or distort them by changing aspect ratio. Instead, I want to keep each image intact and add padding (preferably white) around it to make it square.

I’m looking for a Windows 7 solution that can do this in bulk, ideally something simple for non-Photoshop scripting users.

Originally by Photography Stack Exchange contributor. Source · Licensed CC BY-SA 4.0

Photography Stack Exchange contributor

10y ago

2 Answers

4

I'd recommend Imagemagick. Something like this should work (untested)

FOR %a in (*.jpg) DO convert %a -resize 600x600 -background black -gravity center -extent 600x600 square_%a

Full steps to get this working when you're unfamiliar with scripting are as follows (written for Windows, but similar steps exists for Ubuntu and Mac OS):

  1. Download ImageMagick.
  2. Make a copy of the files you want to work on in a new folder (just in case something goes wrong).
  3. Open the command prompt through the Windows start menu.
  4. Navigate to the folder created in step 2 by typing cd path/to/new/work/folder into the command prompt.
  5. List all the files in the folder with the command dir.
  6. Try out the ImageMagick command on one file to see if the results are satisfactory. Adjust the file_name0001.jpg part to the filename of the image you want to try the script on (e.g. DSC1001.jpg) and write below line in the command prompt:
    convert file_name0001.jpg -resize 600x600 -background black -gravity center -extent 600x600 square_output.jpg

  7. Adjust the options as required. When you're satisfied with the end result you can run the command in a loop over all jpg files. In below command I use the same option values as in step 6 as an example.
    FOR %a in (*.jpg) DO convert %a -resize 600x600 -background black -gravity center -extent 600x600 square_%a

    • This command loops over all files in the folder of step 4 that end in .jpg.
    • Every file that ends in .jpg is put through the ImageMagick command of step 6.
    • After processing the ImageMagick command prepends square_ to the filename and saves the processed file. The original file remains untouched.

Originally by user5477. Source · Licensed CC BY-SA 4.0

user5477

10y ago

0

AI Answer

Generated from our catalog & community — verify before relying on it.

A good option is ImageMagick, which can batch-process images by resizing them to fit within a square and then adding background padding so nothing gets cropped or stretched.

Typical workflow:

  1. Install ImageMagick.
  2. Copy your originals to a separate folder first.
  3. Open Command Prompt and go to that folder.
  4. Test on one image before running the batch.

Example batch command from the community:

FOR %a in (*.jpg) DO convert %a -resize 600x600 -background white -gravity center -extent 600x600 square_%a

What this does:

  • -resize 600x600 fits the image inside a 600×600 box while preserving aspect ratio.
  • -background white sets the padding color.
  • -gravity center centers the image.
  • -extent 600x600 expands the canvas to a square.
  • square_%a writes a new file so your originals stay untouched.

If you use the command directly in Command Prompt, %a is correct. If you save it in a .bat file, you would normally use %%a instead.

UniqueBot

AI

10y ago

Your Answer