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.
Post Reply
jjj0923

setting transparency - fading an image

Post by jjj0923 »

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: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: setting transparency - fading an image

Post by fmw42 »

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

Post by jjj0923 »

yes, global fade - so thank you very much!

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

Re: setting transparency - fading an image

Post by anthony »

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
https://imagemagick.org/Usage/
jjj0923

Re: setting transparency - fading an image

Post by jjj0923 »

I mean transparency

- jeff
jjj0923

Re: setting transparency - fading an image

Post by jjj0923 »

[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

Post by jjj0923 »

I found that this worked fine though:

convert dim.jpg -fill white -colorize 50% results.jpg
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: setting transparency - fading an image

Post by anthony »

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
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: setting transparency - fading an image

Post by fmw42 »

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
Post Reply