The standard way to deal with images and mainly icons in php-gtk is using XPMs. XPM is short for XPixMap and describes an ASCII image format as well as a C library for dealing with the images. Originally the format was developed because the X libraries just had support for 1 bit depth images, the XBM (X BitMap) which is just not enough for applications on a graphical system. Although it is has not been standardized by the X Consortium, it is the de facto standard for icons in X. In this tutorial we will omit the library because we're programming in php and not in C.
The XPM format was designed to fit the special need for icons:
An icon in XPM format is just an ASCII file which can be edited with a normal text editor. As it was designed to be included in C sources, the only content is a C styled array with the image information. You can even have comments in the file - it's C source.
The basic format of a XPM is an array composed as follows:
Note that the header comment with only the word XPM in it is required.
I leave out the Extension strings as we don't need them here.
/* XPM */
static char * <pixmap name>[] = {
"Values-string",
"Colors-strings",
"Pixel-strings"
};
The Values-string has to contain four integer values:
First it may be strange that one has to define the number of characters per pixel, but this becomes clear if you consider the following: Each pixel is represented by a char, e.g. "b", with "b" having the color blue. Now you want another pixel in red, so you give it the char "r" and define "r" being the red color. The ASCII standard defines 128 chars, and with an extended codepage of 255 you would still be limited to somewhat of 250 colors (you can't use quotes and some other chars). To avoid this limitation you can use more than one char to describe a pixel and a color: If you use 2 chars per pixel it is possible to use about 250x250 = 62500 colors by defining pairs of chars to be one color, e.g. "mr" being a medium red and 'db' being a dark blue.
The Colors-strings contains as many strings as there are colors.
Each string has the following format:
The chars value is one or more chars (depending on the
number of characters setting) which define the "pixel name"
of the color. A key can have one of the following values:
"chars key value [key value]*"
"r m white c red", "b m black c blue" |
The Pixel-strings are height string of which each is width * chars per pixel wide.
Ejemplo 2.1. A small sample XPM
/* XPM */ static char * dot[] = { "5 5 2 1", ". c None", "X c Red", " X ", " XXX ", "XXXXX", " XXX ", " X ", }; |
As you probably don't want to create these images by hand, here is a list of programs which support the creation of XPMs: