GD IO

Read and write GD images.

The GD image format is a proprietary image format of libgd.  It has to be regarded as being obsolete, and should only be used for development and testing purposes.

Structure of a GD image file

  • file header
  • color header (either truecolor or palette)
  • image data

All numbers are stored in big-endian format.

File header structure

signature1 word (“\xFF\xFE” for truecolor, “\xFF\xFF” for palette)
width1 word
height1 word

Truecolor image color header

truecolor1 byte (always “\001”)
transparent1 dword (ARGB color)

Palette image color header

truecolor1 byte (always “\0”)
count1 word (the number of used palette colors)
transparent1 dword (ARGB color)
palette256 dwords (RGBA colors)

Image data

Sequential pixel data; row-major from top to bottom, left to right:

  • 1 byte per pixel for palette images
  • 1 dword (ARGB) per pixel for truecolor images
Summary
GD IORead and write GD images.
Functions
gdImageCreateFromGdgdImageCreateFromGd is called to load images from gd format files.
gdImageCreateFromGdPtr
gdImageCreateFromGdCtxReads in a GD image via a gdIOCtx struct.
gdImageGd
gdImageGdPtr

Functions

gdImageCreateFromGd

gdImagePtr gdImageCreateFromGd (FILE *inFile)

gdImageCreateFromGd is called to load images from gd format files.  Invoke gdImageCreateFromGd with an already opened pointer to a file containing the desired image in the gd file format, which is specific to gd and intended for very fast loading.  (It is not intended for compression; for compression, use PNG or JPEG.)

gdImageCreateFromGd returns a gdImagePtr to the new image, or NULL if unable to load the image (most often because the file is corrupt or does not contain a gd format image).  gdImageCreateFromGd does not close the file.  You can inspect the sx and sy members of the image to determine its size.  The image must eventually be destroyed using gdImageDestroy.

Variants

gdImageCreateFromGdPtr creates an image from GD data (i.e. the contents of a GD file) already in memory.

gdImageCreateFromGdCtx reads in an image using the functions in a gdIOCtx struct.

Parameters

infileThe input FILE pointer

Returns

A pointer to the new image or NULL if an error occurred.

Example

gdImagePtr im;
FILE *in;
in = fopen("mygd.gd", "rb");
im = gdImageCreateFromGd(in);
fclose(in);
// ... Use the image ...
gdImageDestroy(im);

gdImageCreateFromGdPtr

gdImagePtr gdImageCreateFromGdPtr (int size,
void *data)

Parameters

sizesize of GD data in bytes.
dataGD data (i.e. contents of a GIF file).

Reads in GD data from memory.  See gdImageCreateFromGd.

gdImageCreateFromGdCtx

gdImagePtr gdImageCreateFromGdCtx (gdIOCtxPtr in)

Reads in a GD image via a gdIOCtx struct.  See gdImageCreateFromGd.

gdImageGd

void gdImageGd (gdImagePtr im,
FILE *outFile)

gdImageGdPtr

void * gdImageGdPtr (gdImagePtr im,
int *size)
gdImagePtr gdImageCreateFromGd (FILE *inFile)
gdImageCreateFromGd is called to load images from gd format files.
gdImagePtr gdImageCreateFromGdPtr (int size,
void *data)
gdImagePtr gdImageCreateFromGdCtx (gdIOCtxPtr in)
Reads in a GD image via a gdIOCtx struct.
gdIOCtx structures hold function pointers for doing image IO.
void gdImageGd (gdImagePtr im,
FILE *outFile)
void * gdImageGdPtr (gdImagePtr im,
int *size)
The data structure in which gd stores images.
void gdImageDestroy (gdImagePtr im)
gdImageDestroy is used to free the memory associated with an image.
Close