Saturday, April 27, 2024
184
rated 0 times [  184] [ 0]  / answers: 1 / hits: 147318  / 1 Year ago, thu, april 6, 2023, 4:17:38

I want to scale all images in a given folder to the same width (but different appropriately scaled heights). How can I do this using a GUI-based or command-line tool?



For bonus points, is it possible to restrict which images are scaled based on their initial width (that is, only scale images that have a width > x and/or a width < y)?


More From » image-processing

 Answers
5

This is very easy to do with imagemagick. You should be able to install it in the Software Center. I would suggest it for batch processing of images.



The batch resizing is incredibly simple (I tested it with Ubuntu 11.10). Use the following command to resize every .jpg file to 200 pixel width, keeping the aspect ratio:



$ convert '*.jpg[200x]' resized%03d.png


you can maintain the filename by using -set option. Ex:



convert "images/*.jpg[250x]" -set filename:base "%[basename]" "images/new_folder/%[filename:base].jpg"


If you have more files you should use with find



find /folder -iname '*.JPG' -exec convert {} -verbose -set filename:base "%[basename]" -resize 1920x1080> "/folder/images/%[filename:base].JPG" ;


This is only scratching the surface of the power of imagemagick. Resizing can be tuned endlessly. For more advanced resizing you have to use the -resize option.



You can limit the resizing to shrinking:



$ convert '*.jpg[300x>]' thumb-300-%03d.png


or enlarging:



$ convert '*.jpg[300x<]' thumb-300-%03d.png


Have look at the geometry documentation to see more options.


[#38529] Thursday, April 6, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
bunsistent

Total Points: 198
Total Questions: 108
Total Answers: 121

Location: Monaco
Member since Sun, Jan 16, 2022
2 Years ago
;