1
votes

I'm trying to make a gradient blending effect of two images (or more). But the problem is that my images have transparency.

I have to images : Image to blend at left Image to blend at right

I want to blend these two pictures so that the red one will be on the left, and the blue one on the right, with a gradient blending effect.

Until now, I used to apply a gradient mask on the blue one, for example this : Blue image mask

Blue image mask

... and put it atop the red one. This works perfectly for photos, but when the images have transparency, i got this :

Gradient Blending Test

So here we can see the gradient blending of the blue image, but we can see the red one through the transparent blue border. :(

I can't find a solution to make a good gradient blending effect that works on transparent images. I'm using imagemagick (with PHP), but I can't find the solution even on Gimp or Photoshop...

Do you know a good method to do that ?

Thanks !

PS : Resources : Red picture Red picture

Blue picture Blue picture

Mask black&white Mask of the blue picture (black & white)

Mask transarent&white Mask of the blue picture (transparent & white)

1
Can you provide the actual images without the checkerboard underlay please?Mark Setchell
Of course ! I edited the question !Thaledric

1 Answers

2
votes

Do you know a good method to do that ?

I would suggest isolating the alpha channels from the base image, then composite the two images against the mask.

# Disable alpha channel, and composite without alpha
convert red.png -alpha off red_base.png
convert blue.png -alpha off blue_base.png
convert blue_base.png black_mask.png -alpha Off \
        -compose CopyOpacity -composite \
        red_base.png -compose DstOver -composite base_out.png

Base composite

Repeat with the extracted alpha channel.

convert red.png -alpha extract red_mask.png
convert blue.png -alpha extract blue_mask.png
convert blue_mask.png black_mask.png -alpha Off \
        -compose CopyOpacity -composite \
        red_mask.png -compose DstOver -composite mask_out.png

Alpha channel composite

And finally apply the generated mask as the new alpha channel.

convert base_out.png  mask_out.png -alpha Off \
        -compose CopyOpacity -composite output.png

Finial composite