Search code examples
imagemagick

Merging two images with ImageMagick Convert -combine option Changes Colors


I am trying to merge two images into one. One image has a grid: CDC Boys BMI and the other image has data points: Data Points

using the command:

convert -combine -verbose -clamp Boys_BMI.png Ipc2eAOT.png new.png

I get this information:

Boys_BMI.png PNG 1700x2200 1700x2200+0+0 8-bit Palette sRGB 33c 198982B 0.047u 0:00.040
Ipc2eAOT.png PNG 1700x2200 1700x2200+0+0 8-bit TrueColor sRGB 16711B 0.031u 0:00.032
Boys_BMI.png=>new.png PNG 1700x2200 1700x2200+0+0 8-bit sRGB 198982B 2.734u 0:00.328

and the resulting image looks like this: Merged Image

Is there a way for the merged image (new.png) to keep the original colors from the original two images?

Thank you, Roberto


Solution

  • -combine is the wrong method to use. It combines channels, not images. What you want to do in Imagemagick is make white into transparent in your points image and then -composite it over the grid image.

    Also your syntax is incorrect. You should read the images right after convert and before any operations.

    convert grid.png \( points.png -transparent white \) -compose over -composite merged.png
    

    enter image description here