How to resize images with awk and convert

If photos in a directory are too large, you may want to use a script to automatically convert all the files into another format. AWK and convert tools can help you. The following command should convert all the files with JPG extension into 1024×680 images.

mkdir converted
cd converted
ls ../*.JPG | awk '{print "convert " $1 " -resize 1024x680 " substr($1, 4, length($1)-7)".jpg "} ' > runme.sh
chmod 755 runme.sh
./runme.sh
rm -f runme.sh

The executable convert is part of ImageMagick package.

Please follow and like us:
This entry was posted in Linux, photos and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *