setting transparency - fading 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.
jjj0923

setting transparency - fading an image

Postby jjj0923 » 2010-07-27T06:31:26-07:00

I've read about the opague feature and wondered is there's a simple way to fade an entire image by some percentage instead of attempting to fade each color separately?

thanks in advance...

Jeff

User avatar
fmw42
Posts: 15272
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA
Contact:

Re: setting transparency - fading an image

Postby fmw42 » 2010-07-27T10:00:45-07:00

Do you mean a global fade so all pixels have the same transparency or do you mean a gradient fade so that it is more transparent on one side than the other?

If the former, then this will set the opacity to 25% (75% transparent)

convert <image> -alpha on -channel a -evaluate set 25% result.png

jjj0923

Re: setting transparency - fading an image

Postby jjj0923 » 2010-07-27T11:25:25-07:00

yes, global fade - so thank you very much!

Jeff

User avatar
anthony
Posts: 8736
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia
Contact:

Re: setting transparency - fading an image

Postby anthony » 2010-07-27T18:12:17-07:00

Also do you mean fade to a color (like white or black) Also known as de-contrasting.
Or do you mean to transparency?

To a color you can use -colorize. for example

Code: Select all

convert input  -fill black -colorize 50%  output

That will fade the image to black by overlaying a 50% transparent black.
It also will not 'fade' any fully-transparent areas in the image toward black.

See IM examples, Colorize

A more controls greyscale fading can be achieved using Reversed Level Adjustments
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
http://www.imagemagick.org/Usage/

jjj0923

Re: setting transparency - fading an image

Postby jjj0923 » 2010-07-28T05:12:01-07:00

I mean transparency

- jeff

jjj0923

Re: setting transparency - fading an image

Postby jjj0923 » 2010-07-29T10:28:43-07:00

[root@localhost seo-images]# convert dim.jpg -alpha on -channel a -evaluate set 50% results.jpg
convert: unrecognized option `-alpha'.


??? - what now?

jjj0923

Re: setting transparency - fading an image

Postby jjj0923 » 2010-07-29T10:31:44-07:00

I found that this worked fine though:

convert dim.jpg -fill white -colorize 50% results.jpg

User avatar
anthony
Posts: 8736
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia
Contact:

Re: setting transparency - fading an image

Postby anthony » 2010-07-29T19:15:42-07:00

jjj0923 wrote:I found that this worked fine though:

convert dim.jpg -fill white -colorize 50% results.jpg


That is not transparency fading, but fading to 'white'.

For a image destined for viewing on a white background such as in a browser, that will work fine, and even work better for older Internet Explorers that did not handle PNG transparency right. Or for JPEG images which does not handle transparency at all!.

-alpha replaces +/-matte functionality, providing many.

-matte is equivelent to -alpha set which is what you should be using.

So try this...

Code: Select all

convert dim.jpg -matte -channel a -evaluate set 50% results.jpg


You should NOT use -alpha on unless you know what you are doing. It is too basically too simple!

ASIDE: For new images -alpha set and -alpha on are equivelent. But for old images possibility containing old alpha channels -alpha on can cause problems you should use -alpha set, which will ensure alpha is present, but does not change the current look of the image if an old alpha channel was present.

For more details see IM Examples, Basics, Controlling Image Transparency
http://www.imagemagick.org/Usage/basics/#alpha
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
http://www.imagemagick.org/Usage/

User avatar
fmw42
Posts: 15272
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA
Contact:

Re: setting transparency - fading an image

Postby fmw42 » 2010-07-29T19:42:47-07:00

jjj0923 wrote:[root@localhost seo-images]# convert dim.jpg -alpha on -channel a -evaluate set 50% results.jpg
convert: unrecognized option `-alpha'.


??? - what now?



Your IM version is too old. What version are you using? In old versions use -matte, in newer versions the more correct equivalent is -alpha set


Return to “Developers”

Who is online

Users browsing this forum: No registered users and 2 guests