I have a 24-bit RGB (not RGBA) grayscale image representing a barcode, which I need to process as follows from the command line:

  • Add alpha channel
  • Convert any of the color channels to alpha (doesn't matter which, it's grayscale to begin with)
  • Invert alpha channel
  • Convert image to CMYK + alpha
  • While preserving the alpha channel, fill entire image with a given solid color (e.g. 100%/87%/11%/1%)
  • Overlay resulting image over another CMYK image, at a specific location (let's say 123 px from the top edge of the template, 321 px from the left)

You understand what I'm doing – the point is simply to overlay the barcode over a template image, except the two images are in separate color spaces, and I happen to also need the resulting barcode to have a specific color. My workflow is just a suggestion, I don't really care how I get from A to B.

Oh, and one more thing (not sure if it's relevant): it's safe to assume I have a pure white rectangle on the template where the barcode ends up. Had I been able to use a Photoshop batch command instead, I'd use this assumption to drop the entire alpha channel bungling around, and would've simply colorized the original and overlayed it with multiply on the template; not sure if this is doable in this context.

1 Answer 1


Ok, after a few good hours of fiddling with this I ended up with a solution:

convert template.tif ( barcode.png barcode.png -negate -alpha off -compose copy_opacity -composite -colorspace CMYK +level-colors "cmyk(100%, 87%, 11%, 1%)" ) -geometry +123+321 -compose over -composite output.tif

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.