Previous chapter To contents Next chapter

Chapter 12, Image

The Image module is used to manipulate bit-mapped color images. It can read PPM images and do various manipulations, or it can be used to create completely new images. The created images can be saved as PPM or converted to GIF.

All images handled by this module are stored as 24-bit RGB images. This means that a 1024 pixel wide and 1024 pixel high image will use 1024*1024*3 bytes = 3 megabytes. It is quite easy to mess up and use up all the memory by giving the wrong argument to one of the scaling functions.

Most functions in this module work by creating a new Image and then returning that instead of changing the Image you are working with. This makes it possible to share the same image between many variables without having to worry that it will be changed by accident. This can reduce the amount of memory used.

Many functions in this module work with the 'current color', this can be thought of as the background color if you wish. To change the current color you use 'setcolor'.

Let's look at an example of how this can be used:

#!/usr/local/bin/pike

int main()
{
    write("Content-type: image/gif\n\n");
    object font=Image.font();
    font->load("testfont");
    object image=font->write(ctime(time));
    write(Image.GIF.encode(image));
}
This very simple example can be used as a CGI script to produce a gif image which says what time it is in white text on a black background.

DESCRIPTION
This module adds image-drawing and -manipulating capabilities to pike.

Image.Image Basic image manipulation
Image.Font Creating images from text
Image.Colortable Color reduction, quantisation and dither
Image.Color Color names, objects and conversion
encoding/decoding image files
Image.GIF GIF encoding/decoding capabilities
Image.JPEG JPEG encoding/decoding capabilities (needs libjpeg)
Image.PNG PNG encoding/decoding capabilities (needs libz)
Image.PNM PNM (PBM/PGM/PPM) encoding/decoding capabilities
Image.XFace XFace encoding/decoding capabilities (needs libgmp)
Image.XWD XWD (X-windows dump) decoding capabilities
advanced
Image.X module for supporting X-windows low-level formats, keeping a lot of bit-mending stuff.
$Id: module.pmod,v 1.8 2000/03/22 18:12:19 peter Exp $

NOTE
Image module documentation is based on these file versions:

$Id: blit.c,v 1.37 1999/06/18 19:19:14 mirar Exp $ $Id: blit_layer_include.h,v 1.6 1999/04/13 12:32:11 mirar Exp $ $Id: colors.c,v 1.30 2000/02/03 19:02:22 grubba Exp $ $Id: colortable.c,v 1.77 1999/10/30 11:51:41 mirar Exp $ $Id: colortable.h,v 1.17 1999/04/11 12:55:43 mirar Exp $ $Id: colortable_lookup.h,v 1.9 1999/04/10 02:02:07 mirar Exp $ $Id: dct.c,v 1.14 1999/06/18 19:19:20 mirar Exp $ $Id: any.c,v 1.16 2000/03/22 18:12:19 peter Exp $ $Id: bmp.c,v 1.20 2000/02/03 12:25:18 grubba Exp $ $Id: gif.c,v 1.50 1999/11/14 22:16:08 mast Exp $ $Id: gif_lzw.c,v 1.6 1999/05/30 20:11:14 mirar Exp $ $Id: gif_lzw.h,v 1.7 1999/05/30 20:11:15 mirar Exp $ $Id: ilbm.c,v 1.13 2000/02/03 19:01:29 grubba Exp $ $Id: pnm.c,v 1.20 1999/06/19 11:08:00 mirar Exp $ $Id: x.c,v 1.26 2000/03/27 07:42:35 hubbe Exp $ $Id: xwd.c,v 1.13 2000/01/11 01:42:36 mast Exp $ $Id: font.c,v 1.58 2000/03/25 23:34:32 hubbe Exp $ $Id: image.c,v 1.160 2000/04/09 06:15:17 per Exp $ $Id: image.h,v 1.35 1999/09/25 19:58:48 grubba Exp $ $Id: layers.c,v 1.43 2000/02/22 03:41:27 per Exp $ $Id: matrix.c,v 1.22 2000/04/09 06:15:17 per Exp $ $Id: operator.c,v 1.25 1999/09/14 23:17:15 marcus Exp $ $Id: orient.c,v 1.13 1999/06/19 20:24:48 hubbe Exp $ $Id: pattern.c,v 1.18 1999/07/16 11:44:20 mirar Exp $ $Id: poly.c,v 1.3 1999/07/28 09:26:20 mirar Exp $ $Id: polyfill.c,v 1.30 1999/06/19 20:24:49 hubbe Exp $ Experimental functions.

METHOD
Image.lay

SYNTAX
Image.Layer lay(array(Image.Layer|mapping))
Image.Layer lay(array(Image.Layer|mapping), int xoffset, int yoffset, int xsize, int ysize)

DESCRIPTION
Combine layers.

RETURNS
a new layer object.

SEE ALSO
Image.Layer

METHOD
Image.load,
Image.load_layer,
Image._load

SYNTAX
object(Image.Image) load()
object(Image.Image) load(object file)
object(Image.Image) load(string filename)
object(Image.Layer) load_layer()
object(Image.Layer) load_layer(object file)
object(Image.Layer) load_layer(string filename)
mapping _load()
mapping _load(object file)
mapping _load(string filename)

DESCRIPTION
Helper function to load an image from a file. If no filename is given, Stdio.stdin is used. The result is the same as from the decode functions in Image.ANY.

NOTE
All data is read, ie nothing happens until the file is closed. Throws upon error.

12.1 Image.Image

12.2 Image.Colortable

12.3 Image.Layer

12.4 Image.Font

12.5 Image.colortable

12.6 Image.Poly

12.7 Image.Color

12.8 Image.X

12.9 Image.ANY

12.10 Image.AVS

12.11 Image.BMP

12.12 Image.GD

12.13 Image.GIF

12.14 Image.HRZ

12.15 Image.ILBM

12.16 Image.PCX

12.17 Image.PNG

12.18 Image.PNM

12.19 Image.PSD

12.20 Image.TGA

12.21 Image.XBM

12.22 Image.XCF

12.23 Image.XWD

12.24 Image.JPEG

12.25 Image.TIFF

12.26 Image.TTF

12.27 Image.XFace


Previous chapter To contents Next chapter