Page 1 of 1

Resize, crop and then mask

Posted: 2012-06-11T01:28:54-07:00
by donslund
Hi.

I have some images that I would like to risize to shortest side, then cop the logest side and then put a mask to it.

I have this code:

// resize
$cmd = "convert $image -resize 212x250^ -gravity center -extent 212x250 $new_name";
exec("$cmd");

//mask
$cmd = "composite $new_name $overlay $mask $new_name";
exec("$cmd");

I use PHP.

The first part does resize and crop, but as soon as I add the mask part, it crops the imge to 212x212 pixels.
My mask-image is 212x250 pixels.

Is there another way to do this, maybe in one line of code?

Re: Resize, crop and then mask

Posted: 2012-06-11T09:46:13-07:00
by fmw42
try using convert rather than composite. note the composite and convert commands require the two input images to be reversed relative to each other. I think you have them the wrong way for composite. But this should do it in one command

convert \( image -resize 212x250^ -gravity center -extent 212x250 \) overlay mask -composite result

for this you probably don't need the parens, so this should work

convert image -resize 212x250^ -gravity center -extent 212x250 overlay mask -composite result

presumably the overlay and mask images are also 212x250

Re: Resize, crop and then mask

Posted: 2012-06-12T17:40:24-07:00
by anthony
See also IM Examples,

Cut to Fit (Thumbnails)
http://www.imagemagick.org/Usage/thumbnails/#cut

Composite Masking
http://www.imagemagick.org/Usage/compose/#mask

Or more specifically Paint and Mask
http://www.imagemagick.org/Usage/thumbnails/#paint_mask

Their is also a "mask and paint" technique that seems to work better!
read that whole section for more ideas and techniques.