How can I batch-make mixed-size photos square without distorting them?
Asked 10/22/2018
6 views
2 answers
0
I have a folder of photos with different dimensions and resolutions. I want each output file to be square, but I do not want to crop away content or distort the original image proportions. Ideally the shorter side would be padded with white space so the full image fits inside a square canvas. Is there a good way to do this in batch for many files?
Originally by Photography Stack Exchange contributor. Source · Licensed CC BY-SA 4.0
Photography Stack Exchange contributor
7y ago
2 Answers
3
You can use ImageMagick to resize the image and place it in a larger canvas with a white background. If you use Mac or Linux, you can process files in a for loop:
mkdir output
for i in *.jpg ; do
convert "$i" -resize 4096x4096 -gravity center -background white -extent 4096x4096 "output/${i%.jpg}-processed.jpg"
done
You can use parallel to process multiple files simultaneously:
mkdir output
for i in *.jpg ; do
echo convert \"$i\" -resize 4096x4096 -gravity center -background white -extent 4096x4096 \"output/${i%.jpg}-processed.jpg\"
done | parallel
Originally by user75526. Source · Licensed CC BY-SA 4.0
user75526
7y ago
0
Generated from our catalog & community — verify before relying on it.
Yes. The usual approach is to keep the image’s aspect ratio unchanged, then place it on a square canvas and fill the extra area with white.
A simple batch method is to use ImageMagick. Example:
convert input.jpg -resize 4096x4096 -gravity center -background white -extent 4096x4096 output.jpg
What this does:
-resize 4096x4096scales the photo to fit within a 4096×4096 box without distortion.-background whitesets the padding color.-gravity centercenters the photo on the canvas.-extent 4096x4096expands the canvas to a square, adding white space where needed.
You can run that in a loop to process a whole folder.
If you prefer a GUI, the same idea works in Photoshop or GIMP: create a square canvas, place the image, scale it proportionally with aspect ratio locked, and automate with an action/script if needed.
Cropping is another way to make images square, but if you must preserve the entire image, padding the canvas is the correct method.
Recommended products
UniqueBot
AI7y ago
Your Answer
Related Questions
How can I batch add square padding to images of different sizes and aspect ratios?
How can I extend a photo’s edges to fill a larger canvas in GIMP?
How can I batch-fit mixed portrait and landscape photos onto a square canvas?
How can I batch-convert product photos to square images without cropping on Windows?
How can I batch center-crop mixed-size images to 600×600 PNG files?