how to crop an image with a 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
andreiya
Posts: 3
Joined: 2016-01-26T10:24:55-07:00
Authentication code: 1151

how to crop an image with a mask

Post by andreiya »

Hi everyone,
I'm trying to do a simple images process, but my level of english and programing is low and is hard for me understand the imagemagick guide. I reviewed Fred's ImageMagick Scripts and neither found any solution.

I want to cut an image with a mask. This is my flow program

1 receive the image to mask and it's size
2 place the mask in the position that i want over the image
3 apply the mask to cut the shape
4 merge the result in other image on the desire position

I want to extract only the shape of the mask. I move the mask because in my image the original is bigger or smaller that mask(the image size to mask will change dynamically ), in case the size of image and mask be the same i don't move nothing.
In this case the mask cut all rose, but some tome i want cut only a part of the rose, for that move the mask to area to crop.
What can i do?

P.D:
My O.S is ubuntu and imagemagick version is:

Version: ImageMagick 6.8.9-9 Q16 x86_64 2015-08-06 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC
Features: DPC Modules OpenMP
Delegates: bzlib djvu fftw fontconfig freetype jbig jng jpeg lcms lqr ltdl lzma openexr pangocairo png tiff wmf x xml zlib




Image
Image
Image
Image
Image
Image
Last edited by andreiya on 2016-01-26T14:15:43-07:00, edited 3 times in total.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: how to crop an image with a mask

Post by Bonzo »

Your last 3 mages are not displayed - need to change the privacy settings on dropbox?
andreiya
Posts: 3
Joined: 2016-01-26T10:24:55-07:00
Authentication code: 1151

Re: how to crop an image with a mask

Post by andreiya »

Bonzo wrote:Your last 3 mages are not displayed - need to change the privacy settings on dropbox?
The images are public and I saw fine in the posting preview :shock:
I have reupload to imgur and I hope that works.
P.D: I visited your page, It 's fine, thanks for sharing
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: how to crop an image with a mask

Post by snibgo »

andreiya wrote:I want to cut an image with a mask.
I think you want to make some pixels transparent. Where the mask is black, make them transparent. Do this with "copy-opacity", for example:

Code: Select all

convert rose: mask.png -compose copy-opacity -composite out.png
Where the mask is 50% gray, pixels will be 50% opaque.
snibgo's IM pages: im.snibgo.com
andreiya
Posts: 3
Joined: 2016-01-26T10:24:55-07:00
Authentication code: 1151

Re: how to crop an image with a mask

Post by andreiya »

Thanks snibgo, I´m going to sleep. Tomorrow try your advice and repost
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: how to crop an image with a mask

Post by Bonzo »

P.D: I visited your page, It 's fine, thanks for sharing
Thank you
Post Reply