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?
Creating a thumbnail of specified resolution
Re: Creating a thumbnail of specified resolution
Try:
Code: Select all
convert input.jpg -gravity center -crop 768x768+0+0 -resize 100x100 output.jpg
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Creating a thumbnail of specified resolution
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
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?
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?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Creating a thumbnail of specified resolution
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
convert image -resize "100x100^" -gravity center -crop 100x100+0+0 +repage result
Re: Creating a thumbnail of specified resolution
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.)
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.)