[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Dvipng] accessing alpha channel

From: John Hunter
Subject: Re: [Dvipng] accessing alpha channel
Date: Sun, 22 May 2005 11:49:01 -0500
User-agent: Gnus/5.090013 (Oort Gnus v0.13) Emacs/21.3 (i386-pc-linux-gnu)

>>>>> "Jan-Åke" == Jan-Åke Larsson <address@hidden> writes:

    Jan-Åke> Bob McElrath wrote:
    >> I use the following sequence of commands using python's Imaging
    >> library: im = Image.open(os.path.join(workingDir, imname)) im2
    >> = Image.new('RGBA', (im.size[0], im.size[1]), (255,255,255))
    >> im2.paste(im, (0, 0)) To explicitly create an alpha channel I
    >> use: alpha = ImageChops.invert(im.convert('L')) im =
    >> im.putalpha(alpha) This creates a PNG with a proper alpha
    >> channel.  I would VERY much like it if dvipng did this for me.
    >> I would love it if you could hack it in to dvipng.

    Jan-Åke> Unless I am mistaken, the CVS version of dvipng does
    Jan-Åke> create a proper-alpha PNG if you use '-bg Transparent'
    Jan-Åke> (capital T). This is to be released very soon as
    Jan-Åke> dvipng-1.6. Please try it out, I'd like to remove any
    Jan-Åke> remaining flaws.

It does not appear to, or I am misunderstanding something.  I got a
CVS checkout today from 

  cvs -z3 -d:ext:address@hidden:/cvsroot/dvipng co dvipng

and here is the summary of my config

** Configuration summary for dvipng 1.5:

   The -d (debug) switch is enabled:        yes
   Your gd is new enough to enable
        the -z (compression) switch:        yes
   Your gd is new enough to enable
        the --truecolor switch:             yes
   Your gd is new enough to enable
        gif support (dvigif):               yes
   FreeType font rendering available:       yes
   T1lib font rendering available:          no

If I then create a png with, for example,

  > /usr/local/bin/dvipng -bg Transparent -fg 'rgb 0.0 0.0 0.0' -D 96 -T tight 
-o somefile.png somefile.dvi

and load the PNG into an array, all the values for the alpha channel
are either 0 or 1.  To overlay this image on an arbitrary background,
I would expect the alpha for the pixels on the edge to vary.  Here is
what I am doing (X is a MxNx4 array loaded from the png, and r,g,b are
the colors I want my text to be when I overlay it onto my own image

    # I ignore the r,g,b channels of X because they have foreground
    # and background color information in them which is not appropriate
    # for overlay on an arbitrary background
    alpha = X[:,:,3]
    Z = zeros(X.shape, Float)
    Z[:,:,0] = r
    Z[:,:,1] = g
    Z[:,:,2] = b
    Z[:,:,3] = alpha

The version number I get from dvipng cvs still says 1.5.  So I have
the latest -- does the CVS mirror lag behind?

    peds-pc311:~/python/projects/matplotlib> /usr/local/bin/dvipng --version 
This is /usr/local/bin/dvipng 1.5 Copyright 2002-2005 Jan-Ake Larsson
    dvipng 1.5
    kpathsea version 3.4.5
    Copyright (C) 2002-2005 Jan-Ake Larsson.
    There is NO warranty.  You may redistribute this software
    under the terms of the GNU General Public License.
    For more information about these matters, see the files
    named COPYING and dvipng.c.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]