Search code examples
linuxraspberry-piimagemagickcommand-line-interfaceimagemagick-convert

Combine two single color images into one with CLI (imagemagick?)


I'm generating "single" color images (B/W and red/white) of our todo schedule to write images to an 3-color e-ink screen, with my Raspberry Pi. First write the black one, then overwrite with red. This works really great, so no help required there.

But I would also like to have the same image available on a website. So I need to have my red image "overwrite" the black one, so I also have the black/red/white image the e-ink shows, as a png/bmp/jpg/whatever. For now we're just using the black one, but I want my overdue stuff in red as well.

I already have imagemagick for the conversions from SVG to PNG/BMP etc., and I'm guessing it should be able to do this. However, I could not find any examples. It's also hard to define the right search parameters, since a lot of people want to combine two images next to or below eachother, not actually combining them.

Does anyone here know how to do this? (I'm not stuck on ImageMagick, but that's the tool I already use)

My guess would be I'd need to make the white in the red/white transparent, then somehow layer it on top... But how?


Solution

  • Thanks to answers I found elsewhere on transparency, and above here from Bruce on 'composite', I ended up doing:

    convert screen-output-red.png -fuzz 30% -transparent white -fill red -opaque black trans.png
    composite trans.png screen-output.png combo.png
    

    Haven't figured out if I could do it in one step, but this is good enough for now.