6

img1 img2

My problem is the following :

I have several .png files. Each file has a small spot of a certain color. All the files have the same size. My question is how to overlay them together so that the spots of different colors will be a mixture of this colors and one color do not overlap completely the other one? The -flatten option combines images but on the example orange (img1) color will be covered by brown (img2), instead I want a spot of mixing color (brownish).

I tried:

convert -evaluate-sequences mean -- didn't help

convert -layers merge -- didn't help

composite -blend -- help, but can combine only two images

Thanks for any tips

Andrea
  • 11,801
  • 17
  • 65
  • 72
MirrG
  • 406
  • 3
  • 10

1 Answers1

36

Not sure what your images are like, since you only provided 2 whereas I was expecting two input images and one result!

So, let's make two of our own:

convert -size 200x100 xc:none -fill black -draw "circle 80,50 130,50"  black.png
convert -size 200x100 xc:none -fill orange -draw "circle 120,50 170,50"  orange.png

enter image description here enter image description here

Then I guess you want this:

convert orange.png black.png -compose overlay -composite result.png

enter image description here

Or maybe you mean luminize blend mode:

convert orange.png black.png -compose luminize  -composite result.png

enter image description here

If you want to experiment with other blend modes, you can use:

identify -list compose

to get a list of all of them.

Atop
Blend
Blur
Bumpmap
ChangeMask
Clear
ColorBurn
ColorDodge
Colorize
CopyAlpha
CopyBlack
CopyBlue
CopyCyan
CopyGreen
Copy
CopyMagenta
CopyRed
CopyYellow
Darken
DarkenIntensity
DivideDst
DivideSrc
Dst
Difference
Displace
Dissolve
Distort
DstAtop
DstIn
DstOut
DstOver
Exclusion
HardLight
HardMix
Hue
In
Intensity
Lighten
LightenIntensity
LinearBurn
LinearDodge
LinearLight
Luminize
Mathematics
MinusDst
MinusSrc
Modulate
ModulusAdd
ModulusSubtract
Multiply
None
Out
Overlay
Over
PegtopLight
PinLight
Plus
Replace
Saturate
Screen
SoftLight
Src
SrcAtop
SrcIn
SrcOut
SrcOver
VividLight
Xor

If you want to check them all:

for b in $(identify -list compose); do convert -gravity center -pointsize 72 -label "$b" orange.png black.png -compose $b -composite  miff:- ; done | montage -geometry +0+0 miff: montage.png

enter image description here

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • 1
    I believe `-compose Blend -composite` would make sense to the examples provided by OP – emcconville Mar 24 '17 at 17:57
  • 3
    Thanks for the fantastic example images and code to generate it! – Laurin Herbsthofer Jun 14 '22 at 11:50
  • 1
    Nowhere in these blend modes is the one I would expect to be default: direct 50% averaging of the two pixels. white + black = gray, black + red = dark red, white + red = light red, etc. How would I achieve this type of composite? – Myrddin Emrys Sep 16 '22 at 18:57
  • Has to be said this kind of quality answer should be the bench mark that a lot of people should aspire to. – UrbanwarfareStudios Mar 14 '23 at 11:03
  • @UrbanwarfareStudios Thank you. I enjoy doing them. Here are a couple of others https://stackoverflow.com/a/56220630/2836621 and https://stackoverflow.com/a/52307690/2836621 and https://stackoverflow.com/a/51822265/2836621 and https://stackoverflow.com/a/60019059/2836621 and https://stackoverflow.com/a/29011461/2836621 – Mark Setchell Mar 14 '23 at 11:30
  • For anyone looking to clip the first file based on the second whilst keeping the colour of the original image and the shape of the second (mask) then use COMPOSITE_DSTIN. – UrbanwarfareStudios Mar 14 '23 at 12:42