Reputation: 559
I'm trying to make a gradient blending effect of two images (or more). But the problem is that my images have transparency.
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
... and put it atop the red one. This works perfectly for photos, but when the images have transparency, i got this :
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 !
Mask of the blue picture (black & white)
Mask of the blue picture (transparent & white)
Upvotes: 1
Views: 3119
Reputation: 24419
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
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
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
Upvotes: 2