Mass resize images (.jpg/.png/etc) in folder
2019-03-21
Requirements
- imagemagick package installed
Generally, the command for a single file is:
convert [input_image.jpg] -resize [percentage]% [output_image.jpg]
Now, to batch-resize a folder with images we can write a small shell script that converts each image in the folder.
We want the resized images in a subfolder called resized
.
#!/bin/bash
if [ ! -d resized ]; then
mkdir resized
fi
for f in `find . -name "*.JPG"`
do
convert $f -resize 50% resized/$f
done
In the example above, we find all files with .JPG
extension and pass them to the convert command.
Also, see the -resize 50%
part. You might want to adjust 50
to your needs.
Drop that script into the folder, e.g. ~/images/convert_script.sh
and:
cd ~/images/
chmod u+x convert_script.sh
./convert_script.sh