Hello.
I need to partially replace first image by second. Both have transparency. But second image have build-in mask which is flat color (for example magenta). This part should stay untoched from first image and all other must be completely replaced (including transparency). I've tried many different methods but none give correct result.
Most closely to ideal result is:
convert i0.png i1.png -fx "u[1].r==1 && u[1].g==0 && u[1].b==1 && u[1].a==1 ? u[0] : u[1]" r.png
But it very slow and dispose of transparent color which make edges little sharper.
Also simple:
convert i0.png i1.png m.png -compose copy -composite r.png
(m.png is extracted mask from second image)
Doesn't copy alpha channel from second image.... Isn't it should? ("This operator is also very similar to 'Over', except that the transparency of the source image is also copied, replacing the background image completely.")
Is there a correct solution for this? (ImageMagick-7.0.4-Q16 Win7)
Replace/Copy by Color Mask
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Replace/Copy by Color Mask
This works as expected in v6.9.5-3, but not v7.0.3-6.
Create input files:
Composite with v6:
Composite with v7:
This looks like a v7 bug to me.
Create input files:
Code: Select all
%IM%convert -size 200x200 xc:Red gradient: -alpha off -compose CopyOpacity -composite tm_a.png
Code: Select all
%IM%convert -size 200x200 xc:Green gradient: -alpha off -compose CopyOpacity -composite -rotate 90 tm_b.png
Code: Select all
%IM%convert -size 200x200 xc:white -fill Black -draw "circle 100,100 150,100" tm_m.png
Composite with v6:
Code: Select all
%IM%convert tm_a.png tm_b.png tm_m.png -compose Copy -composite tm_out6.png
Composite with v7:
Code: Select all
%IMG7%magick tm_a.png tm_b.png tm_m.png -compose Copy -composite tm_out7.png
This looks like a v7 bug to me.
snibgo's IM pages: im.snibgo.com
Re: Replace/Copy by Color Mask
Thanks, snibgo.
ImageMagick-6.9.7-Q16 did the trick. Copy method worked as expected. Since it's better and faster than "fx" i'll return to v6.
ImageMagick-6.9.7-Q16 did the trick. Copy method worked as expected. Since it's better and faster than "fx" i'll return to v6.