Hello,
I'm trying to create a variation of the command that can composite an image over a background, through a mask, as described here:
http://www.imagemagick.org/Usage/compose/#mask
Instead of use two images saved on disc as the source images, I would like to create the source images in memory. I would like the
background to be a transparent canvas, and the foreground to be a solid canvas that shows through my mask (which is saved on disc
as 'mask.png'. This is what I have tried, but it generates a 'convert: missing an image filename' error:
convert -size 128x128 -alpha transparent canvas: \
-size 128x128 -background '#231F20' canvas: \
mask.png -composite output.png
Any help gratefully received.
Composite images with a mask
- GreenKoopa
- Posts: 457
- Joined: 2010-11-04T17:24:08-07:00
- Authentication code: 8675308
Re: Composite images with a mask
convert -size 128x128 canvas:none canvas:#231F20 mask.png -composite output.png
Re: Composite images with a mask
Thank you for your reply. I get the following errors from the command given:
convert: unable to open image `canvas:none': @ error/blob.c/OpenBlob/2489.
convert: unable to open image `canvas:#231F20': @ error/blob.c/OpenBlob/2489.
convert: missing an image filename `output.png' @ error/convert.c/ConvertImageCommand/2940.
I have ImageMagick version 6.6.0-4.
convert: unable to open image `canvas:none': @ error/blob.c/OpenBlob/2489.
convert: unable to open image `canvas:#231F20': @ error/blob.c/OpenBlob/2489.
convert: missing an image filename `output.png' @ error/convert.c/ConvertImageCommand/2940.
I have ImageMagick version 6.6.0-4.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Composite images with a mask
Your version of IM is very old and doesn't recognise "canvas:". I suggest you upgrade. However, you can use "xc:" instead of "canvas:".
But that command may not do what you want. Perhaps ...
... does.
But that command may not do what you want. Perhaps ...
Code: Select all
convert -size 128x128 xc:#231F20 mask.png -compose CopyOpacity -composite c.png
snibgo's IM pages: im.snibgo.com
Re: Composite images with a mask
Thank you. The command I used, essentially yours, which works is
convert -size 128x128 xc:#231F20 mask.gif -alpha Off -compose CopyOpacity -composite c.png
This assumes mask.gif is a 128x128 greyscale image. Not sure if 'alpha Off' is actually necessary, but the result is a shape on a transparent background, aliased with semi-transparent pixels, which is what I wanted.
convert -size 128x128 xc:#231F20 mask.gif -alpha Off -compose CopyOpacity -composite c.png
This assumes mask.gif is a 128x128 greyscale image. Not sure if 'alpha Off' is actually necessary, but the result is a shape on a transparent background, aliased with semi-transparent pixels, which is what I wanted.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Composite images with a mask
That's good.
"-compose CopyOpacity -composite" will use the mask's opacity, if has opacity. If it doesn't have opacity, it will use the tones to create opacity.
Using "-alpha off" switches off any opacity (if the file has any), thus forcing "-compose CopyOpacity -composite" to use the tones.
"-compose CopyOpacity -composite" will use the mask's opacity, if has opacity. If it doesn't have opacity, it will use the tones to create opacity.
Using "-alpha off" switches off any opacity (if the file has any), thus forcing "-compose CopyOpacity -composite" to use the tones.
snibgo's IM pages: im.snibgo.com