gd.h | |
Color Decomposition | |
gdTrueColorGetAlpha | Gets the alpha channel value |
gdTrueColorGetRed | Gets the red channel value |
gdTrueColorGetGreen | Gets the green channel value |
gdTrueColorGetBlue | Gets the blue channel value |
Effects | The layering effect |
Color Quantization | |
gdPaletteQuantizationMethod | |
Transform | |
gdInterpolationMethod | |
HEIF Coding Format | Values that select the HEIF coding format. |
gdHeifCodec | GD_HEIF_CODEC_UNKNOWN GD_HEIF_CODEC_HEVC GD_HEIF_CODEC_AV1 |
HEIF Chroma Subsampling | Values that select the HEIF chroma subsampling. |
gdHeifCompression | GD_HEIF_CHROMA_420 GD_HEIF_CHROMA_422 GD_HEIF_CHROMA_444 |
Types | |
gdImage | |
gdImagePtr | The data structure in which gd stores images. |
Types | |
gdPointF | Defines a point in a 2D coordinate system using floating point values. |
gdPointFPtr | Pointer to a gdPointF |
Types | |
gdFont | |
gdFontPtr | A font structure, containing the bitmaps of all characters in a font. |
Colors | Colors are always of type int which is supposed to be at least 32 bit large. |
Special Colors | |
Types | |
gdSource | |
gdSourcePtr | Note: This interface is obsolete and kept only for *compatibility. |
Types | |
gdFTStringExtra | |
gdFTStringExtraPtr | A structure and associated pointer type used to pass additional parameters to the gdImageStringFTEx function. |
Types | |
gdPoint | |
gdPointPtr | Represents a point in the coordinate space of the image; used by gdImagePolygon, gdImageOpenPolygon and gdImageFilledPolygon for polygon drawing. |
gdRect | A rectangle in the coordinate space of the image |
gdRectPtr | A pointer to a gdRect |
Color Composition | |
gdTrueColorAlpha | Compose a truecolor value from its components |
WebP | |
gdWebpLossless | Lossless quality threshold. |
GifAnim | Legal values for Disposal. |
gdImageGifAnim | |
Types | |
gdSink | |
gdSinkPtr | Note: This interface is obsolete and kept only for compatibility. |
Accessor Macros | |
gdImageTrueColor | Whether an image is a truecolor image. |
gdImageSX | Gets the width (in pixels) of an image. |
gdImageSY | Gets the height (in pixels) of an image. |
gdImageColorsTotal | Gets the number of colors in the palette. |
gdImageRed | Gets the red component value of a given color. |
gdImageGreen | Gets the green component value of a given color. |
gdImageBlue | Gets the blue component value of a given color. |
gdImageAlpha | Gets the alpha component value of a given color. |
gdImageGetTransparent | Gets the transparent color of the image. |
gdImageGetInterlaced | Whether an image is interlaced. |
gdImagePalettePixel | Gets the color of a pixel. |
gdImageTrueColorPixel | Gets the color of a pixel. |
gdImageResolutionX | Gets the horizontal resolution in DPI. |
gdImageResolutionY | Gets the vertical resolution in DPI. |
Crop | |
gdCropMode | |
Image Comparison |
The layering effect
When pixels are drawn the new colors are “mixed” with the background depending on the effect.
Note that the effect does not apply to palette images, where pixels are always replaced.
gdEffectReplace | replace pixels |
gdEffectAlphaBlend | blend pixels, see gdAlphaBlend |
gdEffectNormal | default mode; same as gdEffectAlphaBlend |
gdEffectOverlay | overlay pixels, see gdLayerOverlay |
gdEffectMultiply | overlay pixels with multiply effect, see gdLayerMultiply |
Note that GD_QUANT_JQUANT does not retain the alpha channel, and GD_QUANT_NEUQUANT does not support dithering.
The data structure in which gd stores images. gdImageCreate, gdImageCreateTrueColor and the various image file-loading functions return a pointer to this type, and the other functions expect to receive a pointer to this type as their first argument.
gdImagePtr is a pointer to gdImage.
(Previous versions of this library encouraged directly manipulating the contents ofthe struct but we are attempting to move away from this practice so the fields are no longer documented here. If you need to poke at the internals of this struct, feel free to look at gd.h.)
A font structure, containing the bitmaps of all characters in a font. Used to declare the characteristics of a font. Text-output functions expect these as their second argument, following the gdImagePtr argument. gdFontGetSmall and gdFontGetLarge both return one.
You can provide your own font data by providing such a structure and the associated pixel array. You can determine the width and height of a single character in a font by examining the w and h members of the structure. If you will not be creating your own fonts, you will not need to concern yourself with the rest of the components of this structure.
Please see the files gdfontl.c and gdfontl.h for an example of the proper declaration of this structure.
typedef struct { // # of characters in font int nchars; // First character is numbered... (usually 32 = space) int offset; // Character width and height int w; int h; // Font data; array of characters, one row after another. // Easily included in code, also easily loaded from // data files. char *data; } gdFont;
gdFontPtr is a pointer to gdFont.
Colors are always of type int which is supposed to be at least 32 bit large.
true colors | ARGB values where the alpha channel is stored as most significant, and the blue channel as least significant byte. Note that the alpha channel only uses the 7 least significant bits. Don’t rely on the internal representation, though, and use gdTrueColorAlpha to compose a truecolor value, and gdTrueColorGetAlpha, gdTrueColorGetRed, gdTrueColorGetGreen and gdTrueColorGetBlue to access the respective channels. |
palette indexes | The index of a color palette entry (0-255). |
special colors | As listed in the following section. |
gdStyled | use the current style, see gdImageSetStyle |
gdBrushed | use the current brush, see gdImageSetBrush |
gdStyledBrushed | use the current style and brush |
gdTiled | use the current tile, see gdImageSetTile |
gdTransparent | indicate transparency, what is not the same as the transparent color index; used for lines only |
gdAntiAliased | draw anti aliased |
Note: This interface is obsolete and kept only for *compatibility. Use gdIOCtx instead.
Represents a source from which a PNG can be read. Programmers who do not wish to read PNGs from a file can provide their own alternate input mechanism, using the gdImageCreateFromPngSource function. See the documentation of that function for an example of the proper use of this type.
typedef struct { int (*source) (void *context, char *buffer, int len); void *context; } gdSource, *gdSourcePtr;
The source function must return -1 on error, otherwise the number of bytes fetched. 0 is EOF, not an error!
’context’ will be passed to your source function.
A structure and associated pointer type used to pass additional parameters to the gdImageStringFTEx function. See gdImageStringFTEx for the structure definition.
Thanks to Wez Furlong.
Represents a point in the coordinate space of the image; used by gdImagePolygon, gdImageOpenPolygon and gdImageFilledPolygon for polygon drawing.
typedef struct { int x, y; } gdPoint, *gdPointPtr;
A pointer to a gdRect
Lossless quality threshold. When image quality is greater than or equal to gdWebpLossless, the image will be written in the lossless WebP format.
Note: This interface is obsolete and kept only for compatibility. Use gdIOCtx instead.
Represents a “sink” (destination) to which a PNG can be written. Programmers who do not wish to write PNGs to a file can provide their own alternate output mechanism, using the gdImagePngToSink function. See the documentation of that function for an example of the proper use of this type.
typedef struct { int (*sink) (void *context, char *buffer, int len); void *context; } gdSink, *gdSinkPtr;
The sink function must return -1 on error, otherwise the number of bytes written, which must be equal to len.
context will be passed to your sink function.
GD_CMP_IMAGE | Actual image IS different |
GD_CMP_NUM_COLORS | Number of colors in pallette differ |
GD_CMP_COLOR | Image colors differ |
GD_CMP_SIZE_X | Image width differs |
GD_CMP_SIZE_Y | Image heights differ |
GD_CMP_TRANSPARENT | Transparent color differs |
GD_CMP_BACKGROUND | Background color differs |
GD_CMP_INTERLACE | Interlaced setting differs |
GD_CMP_TRUECOLOR | Truecolor vs palette differs |
Draws a closed polygon
void gdImagePolygon ( gdImagePtr im, gdPointPtr p, int n, int c )
Draws an open polygon
void gdImageOpenPolygon ( gdImagePtr im, gdPointPtr p, int n, int c )
Draws a filled polygon
void gdImageFilledPolygon ( gdImagePtr im, gdPointPtr p, int n, int c )
Blend two colors
int gdAlphaBlend ( int dst, int src )
Overlay two colors
int gdLayerOverlay ( int dst, int src )
Overlay two colors with multiply effect
int gdLayerMultiply ( int dst, int src )
Set the effect for subsequent drawing operations
void gdImageAlphaBlending ( gdImagePtr im, int alphaBlendingArg )
Selects the quantization method
int gdImageTrueColorToPaletteSetMethod ( gdImagePtr im, int method, int speed )
Set the interpolation method for subsequent operations
int gdImageSetInterpolationMethod( gdImagePtr im, gdInterpolationMethod id )
Get the current interpolation method
gdInterpolationMethod gdImageGetInterpolationMethod( gdImagePtr im )
Variant of gdImageHeifEx which uses the default quality (-1), the default codec (GD_HEIF_Codec_HEVC) and the default chroma subsampling (GD_HEIF_CHROMA_444).
void gdImageHeif( gdImagePtr im, FILE * outFile )
gdImageCreate is called to create palette-based images, with no more than 256 colors.
gdImagePtr gdImageCreate ( int sx, int sy )
gdImageCreateTrueColor is called to create truecolor images, with an essentially unlimited number of colors.
gdImagePtr gdImageCreateTrueColor ( int sx, int sy )
Returns the built-in small font.
gdFontPtr gdFontGetSmall ( void )
Returns the built-in large font.
gdFontPtr gdFontGetLarge ( void )
Sets the style for following drawing operations
void gdImageSetStyle ( gdImagePtr im, int * style, int noOfPixels )
Sets the brush for following drawing operations
void gdImageSetBrush ( gdImagePtr im, gdImagePtr brush )
void gdImageSetTile ( gdImagePtr im, gdImagePtr tile )
See gdImageCreateFromPng for documentation.
gdImagePtr gdImageCreateFromPngSource ( gdSourcePtr inSource )
Gets the exact color of the image
int gdImageColorExactAlpha ( gdImagePtr im, int r, int g, int b, int a )
gdImageWebpEx outputs the specified image to the specified file in WebP format.
void gdImageWebpEx ( gdImagePtr im, FILE * outFile, int quality )
This function writes GIF animation frames to GIF animation, which was initialized with gdImageGifAnimBegin.
void gdImageGifAnimAdd( gdImagePtr im, FILE * outFile, int LocalCM, int LeftOfs, int TopOfs, int Delay, int Disposal, gdImagePtr previm )
void gdImagePngToSink ( gdImagePtr im, gdSinkPtr outSink )
Sets the transparent color of the image
void gdImageColorTransparent ( gdImagePtr im, int color )
Sets whether an image is interlaced
void gdImageInterlace ( gdImagePtr im, int interlaceArg )
Gets a pixel color as stored in the image.
int gdImageGetPixel ( gdImagePtr im, int x, int y )
Gets a pixel color always as truecolor value.
int gdImageGetTrueColorPixel ( gdImagePtr im, int x, int y )
Sets the resolution of an image.
void gdImageSetResolution( gdImagePtr im, const unsigned int res_x, const unsigned int res_y )
Crop an image automatically
gdImagePtr gdImageCropAuto( gdImagePtr im, const unsigned int mode )
Compare two images
int gdImageCompare ( gdImagePtr im1, gdImagePtr im2 )