Flattening composed image
Posted: 2016-11-17T10:07:30-07:00
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!
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!