Page 1 of 1
Resize then crop
Posted: 2011-04-16T19:42:20-07:00
by jusanthermemory
I'm trying to take images that are large and resize them down to 275x275. This isn't working since using -resize is keeping the aspect ratio so what I want to do is resize so that both height and width are a minimum of 275 and then crop the image with dimensions 275x275. I'd like to keep aspect ratio if at all possible but if I can't do it and have it fill up the 275x275 then that's fine as well. Is this possible?
Re: Resize then crop
Posted: 2011-04-16T19:46:54-07:00
by NicolasRobidoux
Re: Resize then crop
Posted: 2011-04-16T20:25:27-07:00
by fmw42
jusanthermemory wrote:I'm trying to take images that are large and resize them down to 275x275. This isn't working since using -resize is keeping the aspect ratio so what I want to do is resize so that both height and width are a minimum of 275 and then crop the image with dimensions 275x275. I'd like to keep aspect ratio if at all possible but if I can't do it and have it fill up the 275x275 then that's fine as well. Is this possible?
convert image -resize "275x275^" -gravity center -crop 275x275+0+0 +repage resultimage
see
http://www.imagemagick.org/script/comma ... p#geometry regarding ^ and other character options.
This resizes according to the smaller of your input image dimensions keeping aspect ratio. Thus the smaller dimension will end up as 275, but the larger dimension will be larger. Thus the crop following the resize.
On Windows you may have to escape the ^ with ^ so that it is ^^ (if the quotes don't help). See
http://www.imagemagick.org/Usage/windows/
Alternately, you can resize to the larger dimension and then pad the image
convert image -resize "275x275" -gravity center -background white -extent 275x275 resultimage
Alternately, you can resize and lose aspect ratio ( and accept some distortion)
convert image -resize "275x275!" resultimage
examples are at
http://www.imagemagick.org/Usage/resize/#fill
Re: Resize then crop
Posted: 2011-04-16T20:46:05-07:00
by jusanthermemory
Thanks both of you for your help and guides. I was fumbling around with the guide posted by NicolasRobidoux using the Cut the Thumbnail to Fit method but wasn't using the original image field. Now that I think about it, that makes no sense. I got it working how I want with "convert image -resize "275x275^" -gravity center -crop 275x275+0+0 +repage resultimage". I actually tried this earlier but I used mogrify and it just made all the images super tiny but switching it out with convert did the trick.
Re: Resize then crop
Posted: 2011-04-16T22:14:27-07:00
by fmw42
mogrify should work, but I suggest using a different directory to store the results. Say your images are in folder1 and you create a new folder2
cd folder1
mogrify -path /pathto/folder2 -format jpg -resize "275x275^" -gravity center -crop 275x275+0+0 +repage *.jpg
The multiple input images are *.jpg or (* for all types). The resulting format/image will be the same name as the input but with type determined by -format, in this case also jpg, but you can change it if you want.
For -format jpg, the +repage is not needed as jpg does not store the virtual canvas. For other types, it is needed, so it does no harm to put that in so as to reset the virtual canvas to the cropped size.
Re: Resize then crop
Posted: 2011-04-17T06:19:22-07:00
by anthony
A summery of all the resize and pad/crop methods are in IM Examples Thumbnailing, starting with "padding".
http://www.imagemagick.org/Usage/thumbnails/#pad
Re: Resize then crop
Posted: 2016-08-24T11:18:49-07:00
by Pgscannell
I use magick.exe. Will that application work the same way as convert.exe does? So would I simply execute:
magick orig_image,jp -resize "275x275" -gravity center -background white -extent 275x275 new_image.jpg
You only need the double-quotes around the -resize parameter and not the -extent one?
Also, what are the possible values for the -gravity parameter?
Thanks,
Paul
Re: Resize then crop
Posted: 2016-08-24T11:34:34-07:00
by snibgo
"magick" works more or less like "convert". See the porting guide for differences:
http://www.imagemagick.org/script/porting.php
For gravity options, type "magick -list gravity". Or see the options documentation
http://www.imagemagick.org/script/comma ... hp#gravity
In previous posts, the resize had a special character, caret ^, hence the quotes.