Making transparent .xpm icons, part 2

Or netpbm to the rescue!

Once Karla had slimed me with the task of converting the image and mask files into a single .xpm file I ran into problems with some of the utilities on offer — some, like Graphic Converter, worked well, but seemed to output 16-bit rather than 8-bit information for each channel.

Help was at hand in the form of netpbm, and the appropriate Darwin Port.

1Convert the mask file from .png to .pxm:

pngtopnm mask.png > mask.ppm

2Convert the image file from .png to .pxm, and then pipe that through the .pxm to .xpm converter, bringing in the alphamask that we've just saved:

pngtopnm image.png | ppmtoxpm -alphamask mask.ppm > image_and_mask.xpm

The resulting .xpm file has transparent pixels where the mask was between 50% and 100% black. Obviously with only 1-bit transparency it'll never look as good as a file with 8-bit transparency, but the requirement called for .xpm files so that was the best we could do.

Post your own comment here: