Page 1 of 1

how to convert a png to transparency in gradients

Posted: 2012-04-11T21:31:53-07:00
by liizii
hi all of you

i have a png file ,and i want to change the file right side to transparency in gradients.

ori. file :
Image

and i want:
Image

how can i do this.


thanks.

Re: how to convert a png to transparency in gradients

Posted: 2012-04-11T21:49:55-07:00
by fmw42
try something like though it may not be the most efficient.


size=`convert 460.png -format "%wx%h" info:`
convert 460.png \( -clone 0 -alpha extract \) \
\( -size $size gradient: -rotate -90 -threshold 20% -blur 20x65535 -level 0x50% \) \
\( -clone 1 -clone 2 -compose multiply -composite \) \
-delete 1,2 -compose copy_opacity -composite 460_grad.png

Adjust the threshold level and/or the first part of the blur.

Re: how to convert a png to transparency in gradients

Posted: 2012-04-11T23:52:23-07:00
by liizii
very thanks

i want to change both side, how?

i try this code, but it not work

Code: Select all

convert 460.png ( -clone 0 -alpha extract ) ( -size 440x431 gradient: -rotate -90 -threshold 10% -blur 30x65535 -level 0x50% ) ( -size 440x431 gradient: -rotate -270 -threshold 30% -blur 70x65535 -level 0x50% ) ( -clone 1 -clone 2 -clone 3 -compose multiply -composite ) -delete 1,2,3 -compose copy_opacity -composite 460_grad.png

Re: how to convert a png to transparency in gradients

Posted: 2012-04-12T00:51:17-07:00
by anthony
Fade transparency on both sides but not top and bottom.

Set a virtual-pixel with transparency on sides but not top and bottom, the blur just alpha channel.
You can then layer adjust the transparency.

This is ALOMST like the examples in IM examples, Thumbnails, Soft and Blurred Edges
http://www.imagemagick.org/Usage/thumbnails/#soft_edges
But using a different virtual pixel setting "VerticalTile"
http://www.imagemagick.org/Usage/misc/#vertical_tile

I'll use the built in rose: image so people can try it...

Code: Select all

  convert rose:  -alpha set -background None -virtual-pixel VerticalTile  \
          -channel A -blur 0x8  -level 50%,100% +channel  soft_sides.png
WARNING: the -level in current IMv6 above is buggy and fails. I have reported this.


You may also like to look at IM Examples, Photo Handling, Overlaping Photos
http://www.imagemagick.org/Usage/photos/#overlap

Re: how to convert a png to transparency in gradients

Posted: 2012-04-12T01:50:45-07:00
by liizii
thanks all of you

Re: how to convert a png to transparency in gradients

Posted: 2012-04-12T11:15:44-07:00
by fmw42
anthony wrote:

Code: Select all

  convert rose:  -alpha set -background None -virtual-pixel VerticalTile  \
          -channel A -blur 0x8  -level 50%,100% +channel  soft_sides.png
All I get is a transparent image?

Is that due to -level problems? What is wrong with -level?

Re: how to convert a png to transparency in gradients

Posted: 2012-04-13T05:42:18-07:00
by anthony
Yes. That was the result I got, and it is because of the bug. The command is correct.


If you use -level 0,100% the operation should be a no-op but instead my tests should it is comming out negated. It did not do this before.

From previous examples of this -level in IMv6 is being actually being applied to alpha values (0=transparent, 1=opaque). The forumla given is ths correct. That is expanding 50% transparency at the edges (from the alpha channel blur) to full transparency while leaving 100% opaque parts 100% opaque, but that is not what is happening due to the bug.

The above example, IS correct, (works with IMv7 alpha test build too)

I'll go in and have a look at IMv6 -level tonight, and see if I can figure out where it is being negated.
Yeap found the fault, Also found that it was using matte values for 'palette' images, fixing that too.

It is now fixed next release, or an SVN IMv6 build.

Code: Select all

convert rose:  -alpha set -background None -virtual-pixel VerticalTile \
            -channel A -blur 0x8  -level 50%,100% +channel soft_sides.png
Image

Note that the gradient is a blur feathering, as such the curve is more of a sigmiodal curve falling quite sharply to zero at the edges. A -sigmoidal contrast can make it less sharp.

Better still look at the other link, which adds a linear gradient...
http://www.imagemagick.org/Usage/photos/#overlap
Or apply the distance gradient feather to this virtual pixel method.
http://www.imagemagick.org/Usage/thumbnails/#soft_edges
Either will avoid ths bug, and also work just as well.

The trick is the 'virtual-pixel' setting that use used to give the image transparent sides, while keeping top and bottom fully-opaque.

Re: how to convert a png to transparency in gradients

Posted: 2012-04-13T10:17:05-07:00
by fmw42
Note that the gradient is a blur feathering, as such the curve is more of a sigmiodal curve falling quite sharply to zero at the edges. A -sigmoidal contrast can make it less sharp.
You can make the gradient linear by changing -blur 0x8 to -blur 24x65535

The 24 is only approximate as r is about 3*sigma.

Re: how to convert a png to transparency in gradients

Posted: 2012-04-15T01:56:13-07:00
by anthony
The VERY large sigm, makes the gaussian blur practically linear (just a square of constant values)
See More about this in Convolve, Mean or Average Filtering using Shape Kernels
http://www.imagemagick.org/Usage/convolve/#mean

In this case the radius (square radius) is the size of the linear gradient produced, after the edge values is 'leveled' to approach zero instead of 50%.

Note as a optimization, a linear morphology gradient will be twice as fast, as you don't need the second vertical 'blur' of the alpha channel.