Convert White to Transparency

I needed this for scripted generation of transparent
images showing rendered text. The rendered text usually
comes out black-on-white, which this tool converts to
black-on-transparent.

Note that this does not merely replace all white pixels
by transparent ones, but it does a full shading using the
grey value of each pixel: it installs a new alpha
channel from the grey values. (Gimp: install layer mask,
copy the grey image into it, invert, apply layer
mask).

This is not equivalent to
pnmtopng -transparent white.

Alpha applied assuming red background

How the GIF looks on red background

Perfectly Convert PNG to GIF

PNG features a full-fledged
alpha channel, making half-transparent images easy
to handle. However, not all web browsers support
it the alpha channel of PNGs, so I wanted GIF images on my web site,
but PNG images as my working copy.

This application
prepares PNGs for conversion to GIF by making
all pixels either opaque or fully transparent.
When you provide a background colour, the resulting
GIF looks just as smoothly embedded as the original
PNG. This works particularly well for antialiased
pictures or text.

The last step needs clarification: apply-alpha-keep='#1'
applies the alpha channel using the given background colour,
but keeps the transparency were the picture is opaque by no more
than 1/15 (specified on a single digit greyscale #0..#f
hexadecimal). Transparency is culled: pixels < 1/15
opacity become fully transparent, all others become fully opaque.

Viewed in an image editor, the result will show up as follows.
You can see the transparency, and also how the antialiasing
to the background is still part of the opaque areas of the image
(you can see the frame around the letters):

Either full transparency is kept or else
the alpha channel is applied.

Fully opaque or fully transparent,
as needed for GIF.

Converted to GIF (e.g. with ImageMagick), this looks as follows
in your browser:

Changes

Version 0.1.149

Version 0.1.148 (no official release)

Code downgrade: make compile with old MS compiler
with broken for() scope.

Version 0.1.144

Bug fix: gcc 3.4+ compilation

Bug fixes: newest Erwin used to support 64-bit machines

Version 0.1.141

Bug fix: reading of paletted images should work now

Feature: Cropping by given coordinates

Feature: Auto-cropping in X direction

Feature: GIF can be written directly. I mainly did this
because my version of ImageMagick produces ridiculously large
GIF files. No quantize algorithm is implemented, so the number
of colours must be limited to 255/256, depending on whether
transparency exists. ImageMagick can quantize (and now, the
program can read back those paletted images...).

Bug fix in the GIF writer.

Version 0.1.86

Bug fix: Erwin had a bug fix, so the instatiated files had to be
repackaged: on some machines, v_char.cpp would not compile.