Multiple opacities in an image

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
adamrobbins2018
Posts: 1
Joined: 2018-09-26T09:35:41-07:00
Authentication code: 1152

Multiple opacities in an image

Post by adamrobbins2018 »

I have a black-and-white image where want to add transparency.
I need multiple transparency levels according to the grey level of each pixel. If a pixel is close to black, it must be opaque (less transparent). If grey, medium transparent, and if white, almost 100% transparent.Is there a way to do this? Does a .png format even support such multiple transparencies?
Thanks for your help in advance.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Multiple opacities in an image

Post by fmw42 »

Yes, PNG supports 8-bit transparency. The command should be

Code: Select all

convert image.png -alpha copy image.png
see
https://imagemagick.org/Usage/masking/#alpha_copy


If that does not work. Then in Unix

Code: Select all

convert image.png \( +clone \) -alpha off -compose copy_opacity -composite image.png
For Windows,

Code: Select all

convert image.png ( +clone ) -alpha off -compose copy_opacity -composite image.png
_____________________

Please, always provide your IM version and platform when asking questions, since syntax may differ. Also provide your exact command line and if possible your images.

See the top-most post in this forum "IMPORTANT: Please Read This FIRST Before Posting" at http://www.imagemagick.org/discourse-se ... f=1&t=9620

If using Imagemagick 7, then see http://imagemagick.org/script/porting.php#cli


For novices, see

http://www.imagemagick.org/discourse-se ... f=1&t=9620
http://www.imagemagick.org/script/comma ... essing.php
http://www.imagemagick.org/Usage/reference.html
http://www.imagemagick.org/Usage/
https://github.com/ImageMagick/usage-markdown
Post Reply