Page 1 of 1

Crop with negative offsets

Posted: 2016-12-14T09:50:55-07:00
by kasheftin
Hi, I'm trying to create backend for https://fengyuanchen.github.io/cropper/ plugin.
I have an image and data with cropping options from this plugin that's like {x:-100,y:200,width:300,height:300} array.
x and y are relative to the top left corner of an image.
The obstacle is that cropping area isn't necessary fit in the image. For example, width or height of the cropping area might be greater than the image's width and height. x and y may be negative. All these cases suppose to extend the cropped image with white color.

Please help to write the correct command for this case.

I tried:
$ convert pic.jpg -crop '300x300-100+200' -extend '300x300' out.jpg
- but this does not work correctly: it gives an image that has white margin from the right side while it should be on the left.

Re: Crop with negative offsets

Posted: 2016-12-14T10:25:52-07:00
by GeeMack
kasheftin wrote:I tried:
$ convert pic.jpg -crop '300x300-100+200' -extend '300x300' out.jpg
- but this does not work correctly: it gives an image that has white margin from the right side while it should be on the left.
You might try using your geometry specifiers with the "-extent" operation and don't even use the "-crop". Something like this might do what you want...

Code: Select all

convert pic.jpg -extent '300x300-100+200' out.jpg
Always remember to let us know which version of ImageMagick you're using.

Re: Crop with negative offsets

Posted: 2016-12-14T10:27:11-07:00
by kasheftin
Thanks a lot, it works!

Re: Crop with negative offsets

Posted: 2016-12-14T17:20:19-07:00
by anthony
There is a cavat with using -extent, for image with transparency...
But as JPEG images have no transparency that should not be a problem for you.

See IM Exmaples
http://www.imagemagick.org/Usage/crop/#extent