OxyScripts.com
Menu spacer Home Tutorials Articles Code Forums irc.freenode.net #oxyscripts
Main (PHP)
Home Forums PHP News PHP Tutorials Articles PHP Code Snippets Contact Us Sysadmin Resources Books Template Shop
3rd Party Streams
SlashDot PHPDeveloper.org PHP.Net
Resources
PHP Manual MySQL Manual Smarty Manual PEAR Manual PHP-GTK Manual Symfony Manual
Code Snippets
Authentication Database Graphics HTTP Miscellaneous Time/Date
Affiliates
Scripts TutorialMan TutorialGuide CodingForums.com PHP Scripts Cheap Web Hosting Affordable Web Hosting Dreamweaver Templates

Search This Site :     PHP Function Reference :
 
About XPM

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:
/* XPM */
static char * <pixmap name>[] = {
"Values-string",
"Colors-strings",
"Pixel-strings"
};
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.

The Values-string has to contain four integer values:

Example: "16 16 8 1" defines an icon of size 16x16 pixels with 8 colors and 1 char for defining one pixel.

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:
"chars key value [key value]*" 
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:

The color value itself can be the following: Different key-value pairs can be concatenated to optimize the image for several visuals
"r m white c red",
"b m black c blue" 
The example would define two colors: A color named "r" which is displayed white on a monochrome display and red on a color display. The second is named "b" and is displayed black on a monochrome visual and blue on a color one.

The Pixel-strings are height string of which each is width * chars per pixel wide.

As you probably don't want to create these images by hand, here is a list of programs which support the creation of XPMs:

 
   Print this page

Top Sponsor
Symantec\'s Norton SystemWorks 2006
Sponsors
CA
Sponsors
AdWords Dominator 125*125
Advertisting


Affiliates
VertexTemplates PHPFreaks CodeWalkers StarGeek DevScripts CGI & PHP Scripts PHP CMS Free Templates

Shopping Rebates   Sell It 4 You   Flash Page Counters   Get Insured
GPS Tracking Service   Charity Donate Info   Web Site Hosting   VOIP Service

Privacy Policy | Links | Site Map | Advertising

All content on OxyScripts.com is (©)2002-2007

 
Powered by Adrastea - Version 1.0.0. Copyright © Rune Solutions, 2004-2005