Re: Creating PNG file with transparency
Bob Friesenhahn <[email protected]> Wed, 8 Oct 2008 11:18:57 -0500 (CDT)
| Newsgroups | gmane.comp.video.graphicsmagick.core |
|---|---|
| Message-ID | <[email protected]> |
On Wed, 8 Oct 2008, Nguyen Vu Hung wrote:
> Hello all,
> In google map[1] , the satellite image and the "road" image[2] are
> separated.The browser then look at the "Opacity" of the "road"
> image[2] and makeit transparent.
> My questions are:
> 1. How to use GM's Image class[0] to make a transparent image like
> google.png2. What does "Opacity: ( 0, 0, 0,255) #000000FF" means in
> the output of gm identify -verbose -verbose google.trans.png. What
> API in GM's Image class do I need?3. Do I need to set "Matte Color:
> grey74" and "Background Color:grey100"[3] if I want to do 1. ?
While most graphics programs use an alpha channel which represents the
degree of transparency, GraphicsMagich has an opacity channel which
represents the degree of opacity (inverse of transparency). An opaque
image has an opacity value of 0 and a completely transparent pixel has
an opacity value of MaxRGB. In the "0, 0, 0,255", the 255 indicates
completely transparent. Similarly, the "FF" is max range in the color
specification and indicates completely transparent.
PNG and GIF have the ability to assign a single color as being the
"transparent". This requires a colormapped image representation.
GraphicsMagick has a special "PNG8" output option to support this
binary transparency.
> A sample code would be nice if you are kind enough.
While I will not write the entire program for you, causing an image
color to be transparent is quite easy to do via the 'transparent'
method of the Image class. For example
image.transparent("white");
will set any white color in the image to transparent. You can
explicity write PNG8 format like
image.write("PNG8:output.png").
You can also create a transparent white canvas image and draw or
composite on top of it, but this may obtain full alpha transparency
rather than simple binary transparency.
Bob
======================================
Bob Friesenhahn
[email protected], http://www.simplesystems.org/users/bfriesen/
GraphicsMagick Maintainer, http://www.GraphicsMagick.org/
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/