Thursday, June 30, 2016

ImageMagick - Resize and Modify Images

Sometimes we want to reduce the size of an image before to upload it somewhere, or do some adjust in a photo, like to rotate it, however when we have tens, hundreds, thousands of pictures, it may give us a lot of work if we do one by one. 

These small examples may help you when you want to resize more pictures. You can change it according to your needs. The produced image will have the name with the prefix new-.
for i in *.JPG; do convert $i -resize 50% new-$i; done
for i in *.png; do convert $i -resize 50% new-$i; done

For example, if you want to define the dimensions of the new image, you can do like below.
for i in *.JPG; do convert $i -resize 1024x768 new-$i; done
for i in *.png; do convert $i -resize 1024x768 new-$i; done

If you need to rotate several pictures. The script is similar.
for i in *.JPG; do convert $i -rotate 90 new-$i; done
for i in *.png; do convert $i -rotate 90 new-$i; done

For more, you can take a look at:
convert --help
and at their website http://www.imagemagick.org/Usage/

No comments:

Post a Comment