After a successful South Tyrol Free Software Conference I wanted to upload some images on the conference website.
Shouldn’t be difficult. The website has a special field to add images of the conference. But! It only accepts images in the exact size of 900 x 684 px and all my images have a size of 2048 x 1367 px
That means I have to resize the images and even to crop them, to fit the dimension required by the website CMS. Doing it with gimp for every single image would take me a long time.
Good there is a command line tool like ImageMagick, which helps me do it in just 2 commands on the bash shell.
In the folder with all my images, which are jpg images, I execute the first command, to resize all images to the nearest dimension:
$ for I in *.jpg; do convert $I -resize 1025×684\> small-$I ; done
All the resized images will have the prefix “small-” in the filename after the command has executed successfully. For example, if the folder contains an image named “image001.jpg”, there should be an additional file called “small-image001.jpg” in the folder as well, now.
The second command will crop the resized images, those with the prefix “small-” in their filename, to the exact size of 900 x 684 px. Cutting away the borders on the left and right side of the image.
$ for I in small-*.jpg; do convert $I -gravity center -crop 900×684+0+0\> cropped-$I ; done
Now, I have the original image named “image001.jpg”, the resized version named “small-image001.jpg” and the final resized and cropped version named “cropped-small-image001.jpg”. And this for every image in the folder.
Instead of hours of clicking around in an application, it took me the execution time of 2 commands, which is just around some seconds! Cool!