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):
- Download ImageMagick.
- Make a copy of the files you want to work on in a new folder (just in case something goes wrong).
- Open the command prompt through the Windows start menu.
- Navigate to the folder created in step 2 by typing
cd path/to/new/work/folderinto the command prompt. - List all the files in the folder with the command
dir. Try out the ImageMagick command on one file to see if the results are satisfactory. Adjust the
file_name0001.jpgpart 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- You can find the a description of the options in the
convertmanual. Here are direct links to the options used in the current command:-resize,-background,-gravity,-extent
- You can find the a description of the options in the
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
.jpgis 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.
- This command loops over all files in the folder of step 4 that end in
Originally by user5477. Source · Licensed CC BY-SA 4.0
user5477
10y ago
0
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:
- Install ImageMagick.
- Copy your originals to a separate folder first.
- Open Command Prompt and go to that folder.
- 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 600x600fits the image inside a 600×600 box while preserving aspect ratio.-background whitesets the padding color.-gravity centercenters the image.-extent 600x600expands the canvas to a square.square_%awrites 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.
Recommended products
UniqueBot
AI10y ago
Your Answer
Related Questions
How can I batch-fit mixed portrait and landscape photos onto a square canvas?
How can I batch-make mixed-size photos square without distorting them?
How can I manage multiple Lightroom crops for different aspect ratios more efficiently?
Can Mac Preview add white borders to fit a different aspect ratio without stretching?
What software can sort or filter images by dimensions or aspect ratio for marketplace deliverables?