Page 1 of 1

Centered crop

Posted: 2009-11-06T09:22:07-07:00
by dargaud
Hello all,
I've been reading about -crop and image geometry for a few hoursas well as wrestling with the examples, but I can't get this right: I would like to get a fixed-sized crop around a point, even it it goes partially outside the image border. For instance I want a resulting Width and Height of 100, around point (30,60), so a crop that goes from (-20,10) to (80,110). I don't care what it fills the gap with. I've been wrestling with the +/- signs and ! in the geometry expression to no avail.

Re: Centered crop

Posted: 2009-11-06T10:50:32-07:00
by fmw42
try

convert image.png -crop 100x100-20+10\! -background lightblue -flatten image_crop_flat.png

see http://www.imagemagick.org/Usage/crop/#crop_viewport

change the background color to whatever you want

Re: Centered crop

Posted: 2009-11-08T20:06:34-07:00
by anthony
for cropping around a specific center point on alternative is to use a distort with a viewport into the distorted image. distort viewport

for example translate the center point to crop around to origin, then viewport around the origin.

Code: Select all

convert logo: -set option:distort:viewport 101x101-50-50 \
            -distort affine '388,226 0,0' +repage  logo_nose.png
Image

substitute logo: for input image\
388,226 for the center point
show: for the output image
and adjust viewport for size.