Crop and resize (doesn't work)

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Bilge
Posts: 9
Joined: 2012-09-05T12:53:29-07:00
Authentication code: 67789

Crop and resize (doesn't work)

Post by Bilge »

I'm using the following command to crop the centre portion of an image and then resize the result.

Code: Select all

convert -gravity center -crop x450 -thumbnail 192x
This completely fails to work and is very frustrating. It takes the first 450 rows from (0,0) instead of from the center and it doesn't bother to thumbnail at all. This is despite -list gravity showing Center is supported and despite -thumbnail working without the -crop argument.

Why does this command just perform a crop from (0,0) origin instead of a crop from center and then a resize?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Crop and resize (doesn't work)

Post by fmw42 »

You have no input image or output image. So we do not know where you have put it. Also you need to specify both width and height and offsets +repage when cropping. If you leave off the offsets, IM will try to crop the image into multiple parts. See http://www.imagemagick.org/Usage/crop/#crop_tile. If you leave off the width, IM will use the width of the input image.

Also it would be nice to know what version of IM and what platform you are using. See viewtopic.php?f=1&t=9620

Try

convert inputimage -gravity center -crop WxH+0+0 +repage -thumbnail 192x outputimage

see
http://www.imagemagick.org/Usage/crop/#crop_gravity
Bilge
Posts: 9
Joined: 2012-09-05T12:53:29-07:00
Authentication code: 67789

Re: Crop and resize (doesn't work)

Post by Bilge »

Simply adding +0 to the crop geometry fixed it but I don't understand why. I guess it's to do with the bizarre default behaviour generating a series.
Last edited by Bilge on 2013-02-18T04:58:53-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Crop and resize (doesn't work)

Post by fmw42 »

As I said above, IM will try to tile crop the image into parts if you leave off the +0+0.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Crop and resize (doesn't work)

Post by anthony »

Specifically

If you do not specify an offset of the area to be cropped it will assume you want to generate 'tiles' of that size.

Gravity only sets where the image offset is to be relative to. It does not specify the offset!

If you do not specify a size (width in this case) it is assumed to be the actual image width.

Aside... when virtual canvases are involved it uses the virtual canvas sizes and positions for these defaults.

See IM Example pages on Crop which goes through what crop does when various settings are left off or various flags are used.
http://www.imagemagick.org/Usage/crop/
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply