Hello,
i want to learn how apply gradient mask on image.
My goal is, for given input image, reach image like this:
I'm using windows version, so help me with syntax please.
Thank you for your time,
(and sorry for english)
m.
Apply gradient mask on image
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Apply gradient mask on image
What version IM? Please supply the input image.
Assuming the input is an opaque tree with transparent background: extract the alpha, create a horizontal gradient of the same size with black on the left, multiply the extracted alpha by the gradient, CopyOpacity this back to the alpha channel.
Assuming the input is an opaque tree with transparent background: extract the alpha, create a horizontal gradient of the same size with black on the left, multiply the extracted alpha by the gradient, CopyOpacity this back to the alpha channel.
snibgo's IM pages: im.snibgo.com
- GeeMack
- Posts: 718
- Joined: 2015-12-01T22:09:46-07:00
- Authentication code: 1151
- Location: Central Illinois, USA
Re: Apply gradient mask on image
Using IM 6.9.7-6 HDRI on Windows 10, and running this in a CMD window, I get the result you described.
Code: Select all
convert input.jpg -alpha set -background none -channel A ^
( +clone -sparse-color barycentric "0,0 white %[w],0 none" ) -compose copyopacity -composite output.png
Then it clones the input image and colors that clone with a gradient going from white on the left to transparent on the right. That makes a mask the same dimensions as your input image.
Then it sets a compose method of "copyopacity" and composites the mask over the input image. It essentially displays your input from 100% where the mask is white down to 0% where the mask is transparent.
This method makes it easy to modify the start and end points for the gradient. You could make the fade start one third in from the left side and run just another third across the width with something like this...
Code: Select all
... ( +clone -sparse-color barycentric "%[fx:w*0.33],0 white %[fx:w*0.66],0 none" ) ...
Code: Select all
... ( +clone -sparse-color barycentric "0,0 white %[w],%[h] none" ) ...
To run this from a BAT script you'd need to change the single percent signs "%" to doubles "%%".