Convert greyscale PNG to transparent PNG
Convert greyscale PNG to transparent PNG
My apologies if this is a simple question, but I've been trolling around the site looking at examples for a few hours and haven't come up with anything yet.
I've got a greyscale image with a gradient of colors:
I want to correlate those gradient values to transparency values, and create a new png image from it. So in the example above, the center would be fully transparent, and it would get progressively less transparent as the image fades toward the edges.
Again, my apologies if this is simple, and many thanks.
Kyle
I've got a greyscale image with a gradient of colors:
I want to correlate those gradient values to transparency values, and create a new png image from it. So in the example above, the center would be fully transparent, and it would get progressively less transparent as the image fades toward the edges.
Again, my apologies if this is simple, and many thanks.
Kyle
Re: Convert greyscale PNG to transparent PNG
Hi,
I'm new on this forum anf french (sorry for my english).
What about :
Tell me
I'm new on this forum anf french (sorry for my english).
What about :
Code: Select all
convert blackandwhite.png -transparent white transparent.png
Re: Convert greyscale PNG to transparent PNG
Thanks so much for your response - that's really close! It gets the white transparent, but I want to get a graduated transparency. So the center should be white, but the pixels that are 90% white should have 90% transparency. That's the part I'm having trouble with - any suggestions?
- GreenKoopa
- Posts: 457
- Joined: 2010-11-04T17:24:08-07:00
- Authentication code: 8675308
Re: Convert greyscale PNG to transparent PNG
I can think of two options to add an alpha channel:
But these probably give you the opposite of what you want, just negate if needed:
In general, you could separate the red, green, and blue layers, add an alpha layer, and recombine. Here, I copied the green channel to create an alpha:
http://www.imagemagick.org/Usage/compose/#copyopacity
http://www.imagemagick.org/Usage/color_basics/#channels
Code: Select all
convert in.png -alpha copy out_1.png
convert in.png +clone -alpha off -compose Copy_Opacity -composite out_2.png
Code: Select all
convert in.png -alpha copy -channel A -negate out_neg1.png
Code: Select all
convert in.png -separate -clone 1 -channel rgba -combine out_neg2.png
http://www.imagemagick.org/Usage/color_basics/#channels
Last edited by GreenKoopa on 2010-11-23T11:25:13-07:00, edited 1 time in total.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Convert greyscale PNG to transparent PNG
IM only seems to support transparency in 32-bit PNG. There are still bugs in limitations to 8-bit with transparency and grayscale with transparency for PNG. So this works, but requires converting to 32-bit
convert 1.png -alpha off -alpha copy -type truecolormatte PNG32:1_alpha.png
see
http://www.imagemagick.org/Usage/formats/#png
convert 1.png -alpha off -alpha copy -type truecolormatte PNG32:1_alpha.png
see
http://www.imagemagick.org/Usage/formats/#png
- GreenKoopa
- Posts: 457
- Joined: 2010-11-04T17:24:08-07:00
- Authentication code: 8675308
Re: Convert greyscale PNG to transparent PNG
fmw42, I was unaware of that PNG limitation, so thank you for the warning. I've also read somewhere that -clone must be used in parentheses, but I haven't (yet) had problem with that either.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Convert greyscale PNG to transparent PNG
The command above does not need parenthesis or clones, but if you do use them for some other command, it is better to use them in parenthesis otherwise you may get unpredicable results.
see
http://www.imagemagick.org/Usage/basics/#parenthesis
http://www.imagemagick.org/Usage/basics/#sequence (for clones)
see
http://www.imagemagick.org/Usage/basics/#parenthesis
http://www.imagemagick.org/Usage/basics/#sequence (for clones)
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Convert greyscale PNG to transparent PNG
The -alpha off is not needed in the above. (it is only needed for this type of processing when used with -compose CopyOpacity)fmw42 wrote:Code: Select all
convert 1.png -alpha off -alpha copy -type truecolormatte PNG32:1_alpha.png
also -alpha shape is recommended as it will also replace the color of the mask.
Code: Select all
convert 1.png -background black -alpha copy -type truecolormatte PNG32:1_alpha.png
http://www.imagemagick.org/Usage/masking/#alpha
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: Convert greyscale PNG to transparent PNG
That's exactly what I was looking for - thanks so much!