1

I have a directory of images that I need to scale them down. I need to maintain the aspect ratio, and at the same time have a predefined width and height so basically I need to fit it in a letter box.

For example, I have this image: Original image

Which I scaled down to this: Scaled image

Is there any application that can do that in Linux? I found online apps but they do a single image at a time which does not scale with the number of images that I have.

I can do that in Python as well by using:

scipy.misc.imresize(img, [width, height])

but this loses the ratio as well.

SiHa
  • 7,830
  • 13
  • 34
  • 43
CS_XYZ
  • 33
  • 7
  • This might be useful: https://stackoverflow.com/questions/273946/how-do-i-resize-an-image-using-pil-and-maintain-its-aspect-ratio – Sash Sinha Nov 02 '17 at 08:14
  • 1
    I would use ImageMagick (i.e., convert -resize WIDTHxHEIGHT), not sure if it can process bunch of images using a single command, however, I believe the overhead of a bash loop and launch of the new process for each conversion would be negligible when compared to the conversion itself (if you don't have really tiny images). – lukas Nov 02 '17 at 08:33

1 Answers1

1

From the terminal:

#!/bin/bash
FILES="/path/*.jpg"
for f in $FILES
do
  convert $f -resize 200x200 -background white -extent 200x200 +repage $f
  # rm "$f"
done

This will overwrite the old image into the new images with the specified size.

Wanderer
  • 1,065
  • 5
  • 18
  • 40