Linux convert utility resize image to EXACT size
Posted by broseAug 7
convert, provided by the ImageMagick package, has good behaviour in the resizing of images. If you were to write, for example:
[brose@allmybase-demo]$ convert -resize ‘1024×768’ in.jpg out.jpg
your image would be resized such that neither dimension exceeded the bounds, but unless the aspect ratio is dead on (convert honours and preserves aspect ratios), your image will not be the exact size you specified.
But, there is a simple fix. Append an exclamation point to the end of the size, like this:
[brose@allmybase-demo]$ convert -resize ‘1024×768!’ in.jpg out.jpg
and convert will do exactly what you ask, even if it means distorting the image by destroying the aspect ratio. This could be pretty handy to someone, so I decided to blog it. Heck, it’ll probably be useful to me again soon when I say, “hmmm… how did I do that again?”. Enjoy.
6 comments
Comment by Donald Ade on August 7, 2009 at 12:21 pm
Good to know especially if my desktop environment is gone. Oh KDE… Don’t ever leave me. I <3 KDE
Comment by jacinto on July 29, 2010 at 10:44 pm
thank you, this helped me a lot.
Comment by i love shell on October 14, 2010 at 6:39 pm
# for i in *.png; do echo $i; done|wc -l
11021
# time (for i in *.png; do echo -resize 128x $i.png $i.resized.png; done)
real 0m2,155s
[..]
Donald: Click, click.. 😉
Comment by Murali on July 21, 2011 at 5:46 am
Thank you very much,
I had been searching for this ! command for a long time….
Once again thank you
Comment by Marius on December 1, 2012 at 7:13 pm
Heh! A saviour! Good work
Comment by DarkXDroid on July 30, 2014 at 2:21 am
Thanks! That’s exactly what I needed