7 Years
Discussion Span
Last Post by Stefano Mtangoo

I don't think PIL can do this. The XPixelMap format is a text based C array and you could probably take bitmap information and create this array and save it. Presumably there are C utilities around that create XPM files, you should be able to run those from within Python.

One of the free picture programs that batch converts to and from the XPM format is PhotoMania from:

Here is an example of a 5x5 red dot in XPM format ...

/* XPM */
static char * dot[] = {
"5 5 2 1",
". c None",
"X c Red",
"  X  ",
" XXX ",
" XXX ",
"  X  ",

Since it's text based, one can simply change the array element
"X c Red"
"X c Blue"
and get a blue dot.

BTW, PIL can read XPM files but not write them.

Edited by vegaseat: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.