Page 1 of 1
Creating a thumbnail of specified resolution
Posted: 2010-01-11T09:33:11-07:00
by hollymcr
I need to create the best quality thumbnail I can, of a given size, from an original image. For the sake of simplicity assume a square thumbnail although that won't always be the case.
So let's say I want a 100x100 thumbnail from a 1024x768 image. What I want to do is crop the image to 768x768 (same aspect ratio as the desired thumbnail), using "center" gravity. Then I want to resize the result to 100x100.
Is there a general way to do this without making assumptions about the original image size or aspect ratio, and without going through multple steps?
Re: Creating a thumbnail of specified resolution
Posted: 2010-01-11T10:44:06-07:00
by Bonzo
Try:
Code: Select all
convert input.jpg -gravity center -crop 768x768+0+0 -resize 100x100 output.jpg
Re: Creating a thumbnail of specified resolution
Posted: 2010-01-11T19:01:59-07:00
by fmw42
add +repage after -crop and use -thumbnail rather than -resize so as to strip the headers and profiles, etc. to make the result smaller.
Re: Creating a thumbnail of specified resolution
Posted: 2010-01-12T03:27:21-07:00
by hollymcr
Almost perfect! (And a lot further than I got on my own, so huge thanks!)
Is it possible to handle the generalised case where I don't know the original image size? Ie I don't know that 768 is the smaller of the two dimensions?
For example, can I start by resizing so that the smallest dimension is 100, then crop to 100x100?
Re: Creating a thumbnail of specified resolution
Posted: 2010-01-12T10:21:59-07:00
by fmw42
see the ^ symbol for the geometry at
http://www.imagemagick.org/script/comma ... p#geometry to resize to the smaller dimension. If on windows, see
http://www.imagemagick.org/Usage/windows/
convert image -resize "100x100^" -gravity center -crop 100x100+0+0 +repage result
Re: Creating a thumbnail of specified resolution
Posted: 2010-01-13T06:36:53-07:00
by hollymcr
That's perfect, thanks!
I had got pretty close but not quite there on my own.
I'd say that for most purposes,
convert image -resize "100x100^" -gravity center -crop 100x100+0+0 +repage result
is the best general way to create a thumbnail, isn't it? (100x100 can be changed to whatever size wanted, of-course.)