Hi there,
I'm using ImageMagick 6.8.9-9 on Linux. What I'm trying to do is compose two images, one with pixel data and the other with an alpha channel data (grayscale image) together. That works fine:
convert src.pnm \( alpha.pnm -colorspace gray -alpha off \) -compose copy-opacity -composite out.png
However, I also want to flatten the image afterwards with a background color and I cannot get that to work for the life of me. What works is if I run two convert commands (one writes a PNG, the other flattens). However, I want to directly write a PNM (no alpha). This all doesn't work (they all produce all-red images):
convert src.pnm \( alpha.pnm -colorspace gray -alpha off \) -compose copy-opacity -composite -background red -flatten out.pnm
convert src.pnm \( alpha.pnm -colorspace gray -alpha off \) -compose copy-opacity -background red -flatten out.pnm
convert -background red src.pnm \( alpha.pnm -colorspace gray -alpha off \) -compose copy-opacity -flatten out.pnm
Any ideas? Thank you so much. Cheers!
Flattening composed image
-
- Posts: 3
- Joined: 2016-04-15T13:12:17-07:00
- Authentication code: 1151
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Flattening composed image
Put -compose over before -flatten. The -flatten is use the last compose method (copy_opacity) rather than over. It needs to be reset after the compose copy_opacity.
Note you also need -composite after copy_opacity.
Note you also need -composite after copy_opacity.
Code: Select all
convert src.pnm \( alpha.pnm -colorspace gray -alpha off \) -compose copy-opacity -composite -background red -compose over -flatten out.pnm