How to resize multiple images at once

Hi! This post is about a common need for everyone. That’s highly probable that, at least once, you needed to resize lots of pictures, either to spare some storage space or just because you needed them to have a specific size for some reason. Below you’ll find a script to do it with no effort 🙂 It is based on my previous script for Overlaying a logo in multiple images at once. Once again we’ll use the “convert” program from the Imagemagick toolkit.
 
resize images in batch
 
The first thing to do is to see the extension of your images. Check if they are in .jpeg, .jpg, .png, .bmp, … and replace the extension in the 10th line of the script.
 
Then, you’ll have to calculate the resizing factor. Imagine that your images had the size of 640×480 and you wanted to reduce them to 256×192. If you compare the size of both you’ll see that the desired size is 40% smaller than the original size (192/480=0.4). Take that value (40%) and replace it in the 11th line. After setting those parameters, you’re ready to go.
#!/bin/bash
echo "theBiTbangtheory.blogspot.com image resizer!"
if [ ! -d ./output ]; then mkdir ./output
fi

echo "Processing"
#resize images
for i in *.jpg;
do convert "$i" -resize 40% ./output/"$i"
echo "$i Done"
done
You can download it here.
 
And basically that’s it! Hope it’s useful for you. 🙂

Did you find this post helpful? Do you wish to contribute to other projects regarding computer science, electronics, robotics or mechatronics that will be posted in this blog? If you wish to do so, you can donate via paypal using the button below. Thanks! 🙂
 

Donate