Resize, crop and then mask

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
donslund
Posts: 7
Joined: 2012-06-11T01:23:00-07:00
Authentication code: 13

Resize, crop and then mask

Post 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?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Resize, crop and then mask

Post 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
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Resize, crop and then mask

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply