Make an image transparent

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
iam8up
Posts: 4
Joined: 2011-05-06T12:10:02-07:00
Authentication code: 8675308

Make an image transparent

Post by iam8up »

I have a script that generates and image and such and I want to overlay this on Google Maps.

The only problem I have now is that I want to make the image (PNG) something like 65% transparent. Can this be done? I'm not sure if I am doing something wrong, as every argument I've tried either gives me no result or something I do not want.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Make an image transparent

Post by fmw42 »

try

convert image.png -alpha set -channel a -evaluate set 65% +channel newimage.png

see http://www.imagemagick.org/Usage/transf ... aluate_set

what IM version, platform and OS?

can you post a link to your image(s)?
iam8up
Posts: 4
Joined: 2011-05-06T12:10:02-07:00
Authentication code: 8675308

Re: Make an image transparent

Post by iam8up »

Thank you very much for the response.

This is the image I want to make transparent.
http://inxwireless.com/work/outage-orig.png

the -alpha argument doesn't take:
-> convert outage-orig.png -alpha set -channel a -evaluate set 65% +channel outage.png
convert: unrecognized option `-alpha'.

convert outage-orig.png -channel a -evaluate set 65% +channel outage.png
http://inxwireless.com/work/output.png

ImageMagick.i386 6.2.8.0-4.el5_5.3
-> cat /etc/redhat-release
CentOS release 5 (Final)
32-bit
Last edited by iam8up on 2011-05-10T11:13:06-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Make an image transparent

Post by fmw42 »

Your input image does not look like the correct link. The page is missing all images.

Your version of IM is too old (over 400 versions old) to use -alpha set and perhaps -evaluate set

If you cannot upgrade IM (highly recommended!), then

try

convert image.png -matte -channel a -evaluate set 65% +channel newimage.png

or

convert image.png -matte -channel a -evaluate set 35% +channel newimage.png

as the alpha channel at that time might be really opacity and not transparency

if that fails, try

convert image.png \( -clone 0 -fill "gray(65%)" -colorize 100% \) -compose copy_opacity -composite result.png

or

convert image.png \( -clone 0 -fill "gray(35%)" -colorize 100% \) -compose copy_opacity -composite result.png
Last edited by fmw42 on 2011-05-10T11:47:42-07:00, edited 1 time in total.
iam8up
Posts: 4
Joined: 2011-05-06T12:10:02-07:00
Authentication code: 8675308

Re: Make an image transparent

Post by iam8up »

I fixed both links to images above, they should work now. Sorry about that.

I tried the first two commands and I don't see any differences between the output images and original.

The third command is missing a quote somewhere, so I did:
-> convert outage-orig.png \( -clone 0 -fill grey -colorize 100% \) -compose copy_opacity -composite result.png
Of which I don't see any change in the image either.

http://inxwireless.com/work/newimage.png
http://inxwireless.com/work/result.png

I'm guessing it has something to do with how the image is colored (alpha, palette, something of that sort). Total guess, mind you!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Make an image transparent

Post by fmw42 »

try this (I fixed the quote and added +matte to turn off any existing alpha channel, sorry about the quote)


convert newimage.png \( -clone 0 -fill "gray(35%)" -colorize 100% \) +matte -compose copy_opacity -composite newimage_result.png

or


convert newimage.png \( -clone 0 -fill "gray(65%)" -colorize 100% \) +matte -compose copy_opacity -composite newimage_result.png


Then drop it on your browser's white background and you should see it look somewhat whiter as it is overlaid on the white background.

This also works for me:

convert newimage.png -matte -channel a -evaluate set 35% +channel newimage_result2.png
iam8up
Posts: 4
Joined: 2011-05-06T12:10:02-07:00
Authentication code: 8675308

Re: Make an image transparent

Post by iam8up »

I upgraded versions as your initial suggestion put. Since there is no repo for it, I had to do it semi-manually. This guide was used and was flawless short of the version (I used 6.6.9)
http://en.citizendium.org/wiki/User:Dan ... k_6.6.2-10

-> convert --version
Version: ImageMagick 6.6.9-8 2011-05-10 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2011 ImageMagick Studio LLC
Features: OpenMP

This worked! Thanks so so much!
convert outage-orig.png \( -clone 0 -fill "gray(35%)" -colorize 100% \) +matte -compose copy_opacity -composite newimage_result.png
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Make an image transparent

Post by fmw42 »

With your new release, the other method should work also and is shorter and faster.

convert newimage.png -alpha set -channel a -evaluate set 35% +channel newimage_result2.png

or


convert newimage.png -alpha opaque -channel a -evaluate set 35% +channel newimage_result2.png
Rye
Posts: 158
Joined: 2013-02-25T10:43:05-07:00
Authentication code: 6789

Re: Make an image transparent

Post by Rye »

fmw42 wrote:try

convert image.png -alpha set -channel a -evaluate set 65% +channel newimage.png

see http://www.imagemagick.org/Usage/transf ... aluate_set

what IM version, platform and OS?

can you post a link to your image(s)?
It works, but there is one problem.
It replaces the "already present transperency" my pictures have with "black".

Any way to keep that transparancy aswell ?
Version: ImageMagick-7.0.7-28-Q16-x64-static http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Make an image transparent

Post by fmw42 »

So what do you want to happen? You want to reduce the opacity of all pixels from whatever they have by 65%. If so, try this

Code: Select all

convert image.png -alpha on -channel a -evaluate multiply 0.65 +channel newimage.png
Rye
Posts: 158
Joined: 2013-02-25T10:43:05-07:00
Authentication code: 6789

Re: Make an image transparent

Post by Rye »

Perfect :)
Version: ImageMagick-7.0.7-28-Q16-x64-static http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
Post Reply