| gd.c | |
| Error Handling | |
| gdSetErrorMethod | |
| gdClearErrorMethod | |
| Creation and Destruction | |
| gdImageCreate | gdImageCreate is called to create palette-based images, with no more than 256 colors. |
| gdImageCreateTrueColor | gdImageCreateTrueColor is called to create truecolor images, with an essentially unlimited number of colors. |
| gdImageDestroy | gdImageDestroy is used to free the memory associated with an image. |
| Color | |
| gdImageColorClosest | Gets the closest color of the image |
| gdImageColorClosestAlpha | Gets the closest color of the image |
| gdImageColorClosestHWB | |
| gdImageColorExact | Gets the exact color of the image |
| gdImageColorExactAlpha | Gets the exact color of the image |
| gdImageColorAllocate | Allocates a color |
| gdImageColorAllocateAlpha | Allocates a color |
| gdImageColorResolve | gdImageColorResolve is an alternative for the code fragment |
| gdImageColorResolveAlpha | |
| gdImageColorDeallocate | Removes a palette entry |
| gdImageColorTransparent | Sets the transparent color of the image |
| gdImagePaletteCopy | |
| gdImageColorReplace | |
| gdImageColorReplaceThreshold | |
| gdImageColorReplaceArray | |
| gdImageColorReplaceCallback | |
| Pixels | |
| gdImageSetPixel | |
| gdImageGetPixel | Gets a pixel color as stored in the image. |
| gdImageGetTrueColorPixel | Gets a pixel color always as truecolor value. |
| Primitives | |
| gdImageAABlend | NO-OP, kept for library compatibility. |
| gdImageLine | Bresenham as presented in Foley & Van Dam. |
| gdImageDashedLine | |
| gdImageBoundsSafe | |
| gdImageChar | Draws a single character. |
| gdImageCharUp | |
| gdImageString | Draws a character string. |
| gdImageStringUp | |
| gdImageString16 | |
| gdImageStringUp16 | |
| gdImageArc | |
| gdImageFilledArc | |
| gdImageEllipse | |
| gdImageFilledEllipse | |
| gdImageFillToBorder | |
| gdImageFill | |
| gdImageRectangle | Draws a rectangle. |
| gdImageFilledRectangle | |
| Cloning and Copying | |
| gdImageClone | Clones an image |
| gdImageCopy | Copy an area of an image to another image |
| gdImageCopyMerge | Copy an area of an image to another image ignoring alpha |
| gdImageCopyMergeGray | Copy an area of an image to another image ignoring alpha |
| gdImageCopyResized | Copy a resized area from an image to another image |
| gdImageCopyRotated | Copy a rotated area from an image to another image |
| gdImageCopyResampled | Copy a resampled area from an image to another image |
| Polygons | |
| gdImagePolygon | Draws a closed polygon |
| gdImageOpenPolygon | Draws an open polygon |
| gdImageFilledPolygon | Draws a filled polygon |
| other | |
| gdImageSetStyle | Sets the style for following drawing operations |
| gdImageSetThickness | Sets the thickness for following drawing operations |
| gdImageSetBrush | Sets the brush for following drawing operations |
| gdImageSetTile | |
| gdImageSetAntiAliased | Set the color for subsequent anti-aliased drawing |
| gdImageSetAntiAliasedDontBlend | Set the color and “dont_blend” color for subsequent anti-aliased drawing |
| gdImageInterlace | Sets whether an image is interlaced |
| gdImageCompare | Compare two images |
| gdAlphaBlend | Blend two colors |
| gdLayerOverlay | Overlay two colors |
| gdLayerMultiply | Overlay two colors with multiply effect |
| gdImageAlphaBlending | Set the effect for subsequent drawing operations |
| gdImageSaveAlpha | Sets the save alpha flag |
| gdImageSetClip | Sets the clipping rectangle |
| gdImageGetClip | Gets the current clipping rectangle |
| gdImageSetResolution | Sets the resolution of an image. |
| gdImagePaletteToTrueColor | Convert a palette image to true color |
gdImagePtr gdImageCreate ( int sx, int sy )
gdImageCreate is called to create palette-based images, with no more than 256 colors. The image must eventually be destroyed using gdImageDestroy().
| sx | The image width. |
| sy | The image height. |
A pointer to the new image or NULL if an error occurred.
gdImagePtr im; im = gdImageCreate(64, 64); // ... Use the image ... gdImageDestroy(im);
gdImagePtr gdImageCreateTrueColor ( int sx, int sy )
gdImageCreateTrueColor is called to create truecolor images, with an essentially unlimited number of colors. Invoke gdImageCreateTrueColor with the x and y dimensions of the desired image. gdImageCreateTrueColor returns a gdImagePtr to the new image, or NULL if unable to allocate the image. The image must eventually be destroyed using <gdImageDestroy>().
Truecolor images are always filled with black at creation time. There is no concept of a “background” color index.
| sx | The image width. |
| sy | The image height. |
A pointer to the new image or NULL if an error occurred.
gdImagePtr im; im = gdImageCreateTrueColor(64, 64); // ... Use the image ... gdImageDestroy(im);
void gdImageDestroy ( gdImagePtr im )
gdImageDestroy is used to free the memory associated with an image. It is important to invoke gdImageDestroy before exiting your program or assigning a new image to a gdImagePtr variable.
| im | Pointer to the gdImage to delete. |
Nothing.
gdImagePtr im; im = gdImageCreate(10, 10); // ... Use the image ... // Now destroy it gdImageDestroy(im);
int gdImageColorClosest ( gdImagePtr im, int r, int g, int b )
Gets the closest color of the image
This is a simplified variant of gdImageColorClosestAlpha where the alpha channel is always opaque.
| im | The image. |
| r | The value of the red component. |
| g | The value of the green component. |
| b | The value of the blue component. |
The closest color already available in the palette for palette images; the color value of the given components for truecolor images.
int gdImageColorClosestAlpha ( gdImagePtr im, int r, int g, int b, int a )
Gets the closest color of the image
| im | The image. |
| r | The value of the red component. |
| g | The value of the green component. |
| b | The value of the blue component. |
| a | The value of the alpha component. |
The closest color already available in the palette for palette images; the color value of the given components for truecolor images.
int gdImageColorExact ( gdImagePtr im, int r, int g, int b )
Gets the exact color of the image
This is a simplified variant of gdImageColorExactAlpha where the alpha channel is always opaque.
| im | The image. |
| r | The value of the red component. |
| g | The value of the green component. |
| b | The value of the blue component. |
The exact color already available in the palette for palette images; if there is no exact color, -1 is returned. For truecolor images the color value of the given components is returned.
int gdImageColorExactAlpha ( gdImagePtr im, int r, int g, int b, int a )
Gets the exact color of the image
| im | The image. |
| r | The value of the red component. |
| g | The value of the green component. |
| b | The value of the blue component. |
| a | The value of the alpha component. |
The exact color already available in the palette for palette images; if there is no exact color, -1 is returned. For truecolor images the color value of the given components is returned.
int gdImageColorAllocate ( gdImagePtr im, int r, int g, int b )
Allocates a color
This is a simplified variant of gdImageColorAllocateAlpha where the alpha channel is always opaque.
| im | The image. |
| r | The value of the red component. |
| g | The value of the green component. |
| b | The value of the blue component. |
The color value.
int gdImageColorAllocateAlpha ( gdImagePtr im, int r, int g, int b, int a )
Allocates a color
This is typically used for palette images, but can be used for truecolor images as well.
| im | The image. |
| r | The value of the red component. |
| g | The value of the green component. |
| b | The value of the blue component. |
The color value.
int gdImageColorResolve ( gdImagePtr im, int r, int g, int b )
gdImageColorResolve is an alternative for the code fragment
if ((color=gdImageColorExact(im,R,G,B)) < 0)
if ((color=gdImageColorAllocate(im,R,G,B)) < 0)
color=gdImageColorClosest(im,R,G,B);in a single function. Its advantage is that it is guaranteed to return a color index in one search over the color table.
void gdImageString ( gdImagePtr im, gdFontPtr f, int x, int y, unsigned char * s, int color )
Draws a character string.
| im | The image to draw onto. |
| f | The raster font. |
| x | The x coordinate of the upper left pixel. |
| y | The y coordinate of the upper left pixel. |
| c | The character string. |
| color | The color. |
void gdImageRectangle ( gdImagePtr im, int x1, int y1, int x2, int y2, int color )
Draws a rectangle.
| im | The image. |
| x1 | The x-coordinate of one of the corners. |
| y1 | The y-coordinate of one of the corners. |
| x2 | The x-coordinate of another corner. |
| y2 | The y-coordinate of another corner. |
| color | The color. |
void gdImageCopy ( gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int w, int h )
Copy an area of an image to another image
| dst | The destination image. |
| src | The source image. |
| dstX | The x-coordinate of the upper left corner to copy to. |
| dstY | The y-coordinate of the upper left corner to copy to. |
| srcX | The x-coordinate of the upper left corner to copy from. |
| srcY | The y-coordinate of the upper left corner to copy from. |
| w | The width of the area to copy. |
| h | The height of the area to copy. |
void gdImageCopyMerge ( gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int w, int h, int pct )
Copy an area of an image to another image ignoring alpha
The source area will be copied to the destination are by merging the pixels.
This function is a substitute for real alpha channel operations, so it doesn’t pay attention to the alpha channel.
| dst | The destination image. |
| src | The source image. |
| dstX | The x-coordinate of the upper left corner to copy to. |
| dstY | The y-coordinate of the upper left corner to copy to. |
| srcX | The x-coordinate of the upper left corner to copy from. |
| srcY | The y-coordinate of the upper left corner to copy from. |
| w | The width of the area to copy. |
| h | The height of the area to copy. |
| pct | The percentage in range 0..100. |
void gdImageCopyMergeGray ( gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int w, int h, int pct )
Copy an area of an image to another image ignoring alpha
The source area will be copied to the grayscaled destination area by merging the pixels.
This function is a substitute for real alpha channel operations, so it doesn’t pay attention to the alpha channel.
| dst | The destination image. |
| src | The source image. |
| dstX | The x-coordinate of the upper left corner to copy to. |
| dstY | The y-coordinate of the upper left corner to copy to. |
| srcX | The x-coordinate of the upper left corner to copy from. |
| srcY | The y-coordinate of the upper left corner to copy from. |
| w | The width of the area to copy. |
| h | The height of the area to copy. |
| pct | The percentage of the source color intensity in range 0..100. |
void gdImageCopyResized ( gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH )
Copy a resized area from an image to another image
If the source and destination area differ in size, the area will be resized using nearest-neighbor interpolation.
| dst | The destination image. |
| src | The source image. |
| dstX | The x-coordinate of the upper left corner to copy to. |
| dstY | The y-coordinate of the upper left corner to copy to. |
| srcX | The x-coordinate of the upper left corner to copy from. |
| srcY | The y-coordinate of the upper left corner to copy from. |
| dstW | The width of the area to copy to. |
| dstH | The height of the area to copy to. |
| srcW | The width of the area to copy from. |
| srcH | The height of the area to copy from. |
void gdImageCopyRotated ( gdImagePtr dst, gdImagePtr src, double dstX, double dstY, int srcX, int srcY, int srcWidth, int srcHeight, int angle )
Copy a rotated area from an image to another image
The area is counter-clockwise rotated using nearest-neighbor interpolation.
| dst | The destination image. |
| src | The source image. |
| dstX | The x-coordinate of the center of the area to copy to. |
| dstY | The y-coordinate of the center of the area to copy to. |
| srcX | The x-coordinate of the upper left corner to copy from. |
| srcY | The y-coordinate of the upper left corner to copy from. |
| srcW | The width of the area to copy from. |
| srcH | The height of the area to copy from. |
| angle | The angle in degrees. |
void gdImageCopyResampled ( gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH )
Copy a resampled area from an image to another image
If the source and destination area differ in size, the area will be resized using bilinear interpolation for truecolor images, and nearest-neighbor interpolation for palette images.
| dst | The destination image. |
| src | The source image. |
| dstX | The x-coordinate of the upper left corner to copy to. |
| dstY | The y-coordinate of the upper left corner to copy to. |
| srcX | The x-coordinate of the upper left corner to copy from. |
| srcY | The y-coordinate of the upper left corner to copy from. |
| dstW | The width of the area to copy to. |
| dstH | The height of the area to copy to. |
| srcW | The width of the area to copy from. |
| srcH | The height of the area to copy from. |
void gdImagePolygon ( gdImagePtr im, gdPointPtr p, int n, int c )
Draws a closed polygon
| im | The image. |
| p | The vertices as array of gdPoints. |
| n | The number of vertices. |
| c | The color. |
void gdImageOpenPolygon ( gdImagePtr im, gdPointPtr p, int n, int c )
Draws an open polygon
| im | The image. |
| p | The vertices as array of gdPoints. |
| n | The number of vertices. |
| c | The color |
void gdImageFilledPolygon ( gdImagePtr im, gdPointPtr p, int n, int c )
Draws a filled polygon
The polygon is filled using the even-odd fillrule what can leave unfilled regions inside of self-intersecting polygons. This behavior might change in a future version.
| im | The image. |
| p | The vertices as array of gdPoints. |
| n | The number of vertices. |
| c | The color |
void gdImageSetAntiAliased ( gdImagePtr im, int c )
Set the color for subsequent anti-aliased drawing
If gdAntiAliased is passed as color to drawing operations that support anti-aliased drawing (such as gdImageLine and gdImagePolygon), the actual color to be used can be set with this function.
gdImageSetAntiAliased(im, gdTrueColorAlpha(0, 0, gdBlueMax, gdAlphaOpaque)); gdImageLine(im, 10,10, 20,20, gdAntiAliased);
| im | The image. |
| c | The color. |
void gdImageSetAntiAliasedDontBlend ( gdImagePtr im, int c, int dont_blend )
Set the color and “dont_blend” color for subsequent anti-aliased drawing
This extended variant of gdImageSetAntiAliased allows to also specify a (background) color that will not be blended in anti-aliased drawing operations.
| im | The image. |
| c | The color. |
| dont_blend | Whether to blend. |
int gdImageCompare ( gdImagePtr im1, gdImagePtr im2 )
Compare two images
| im1 | An image. |
| im2 | Another image. |
A bitmask of Image Comparison flags where each set flag signals which attributes of the images are different.
void gdImageSetClip ( gdImagePtr im, int x1, int y1, int x2, int y2 )
Sets the clipping rectangle
The clipping rectangle restricts the drawing area for following drawing operations.
| im | The image. |
| x1 | The x-coordinate of the upper left corner. |
| y1 | The y-coordinate of the upper left corner. |
| x2 | The x-coordinate of the lower right corner. |
| y2 | The y-coordinate of the lower right corner. |
void gdImageGetClip ( gdImagePtr im, int * x1P, int * y1P, int * x2P, int * y2P )
Gets the current clipping rectangle
| im | The image. |
| x1P | (out) The x-coordinate of the upper left corner. |
| y1P | (out) The y-coordinate of the upper left corner. |
| x2P | (out) The x-coordinate of the lower right corner. |
| y2P | (out) The y-coordinate of the lower right corner. |
void gdSetErrorMethod( gdErrorMethod error_method )
void gdClearErrorMethod( void )
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 )
gdImageDestroy is used to free the memory associated with an image.
void gdImageDestroy ( gdImagePtr im )
Gets the closest color of the image
int gdImageColorClosest ( gdImagePtr im, int r, int g, int b )
Gets the closest color of the image
int gdImageColorClosestAlpha ( gdImagePtr im, int r, int g, int b, int a )
int gdImageColorClosestHWB ( gdImagePtr im, int r, int g, int b )
Gets the exact color of the image
int gdImageColorExact ( gdImagePtr im, int r, int g, int b )
Gets the exact color of the image
int gdImageColorExactAlpha ( gdImagePtr im, int r, int g, int b, int a )
Allocates a color
int gdImageColorAllocate ( gdImagePtr im, int r, int g, int b )
Allocates a color
int gdImageColorAllocateAlpha ( gdImagePtr im, int r, int g, int b, int a )
gdImageColorResolve is an alternative for the code fragment
int gdImageColorResolve ( gdImagePtr im, int r, int g, int b )
int gdImageColorResolveAlpha ( gdImagePtr im, int r, int g, int b, int a )
Removes a palette entry
void gdImageColorDeallocate ( gdImagePtr im, int color )
Sets the transparent color of the image
void gdImageColorTransparent ( gdImagePtr im, int color )
void gdImagePaletteCopy ( gdImagePtr to, gdImagePtr from )
int gdImageColorReplace ( gdImagePtr im, int src, int dst )
int gdImageColorReplaceThreshold ( gdImagePtr im, int src, int dst, float threshold )
int gdImageColorReplaceArray ( gdImagePtr im, int len, int * src, int * dst )
int gdImageColorReplaceCallback ( gdImagePtr im, gdCallbackImageColor callback )
void gdImageSetPixel ( gdImagePtr im, int x, int y, int color )
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 )
NO-OP, kept for library compatibility.
void gdImageAABlend ( gdImagePtr im )
Bresenham as presented in Foley & Van Dam.
void gdImageLine ( gdImagePtr im, int x1, int y1, int x2, int y2, int color )
void gdImageDashedLine ( gdImagePtr im, int x1, int y1, int x2, int y2, int color )
int gdImageBoundsSafe ( gdImagePtr im, int x, int y )
Draws a single character.
void gdImageChar ( gdImagePtr im, gdFontPtr f, int x, int y, int c, int color )
void gdImageCharUp ( gdImagePtr im, gdFontPtr f, int x, int y, int c, int color )
Draws a character string.
void gdImageString ( gdImagePtr im, gdFontPtr f, int x, int y, unsigned char * s, int color )
void gdImageStringUp ( gdImagePtr im, gdFontPtr f, int x, int y, unsigned char * s, int color )
void gdImageString16 ( gdImagePtr im, gdFontPtr f, int x, int y, unsigned short * s, int color )
void gdImageStringUp16 ( gdImagePtr im, gdFontPtr f, int x, int y, unsigned short * s, int color )
void gdImageArc ( gdImagePtr im, int cx, int cy, int w, int h, int s, int e, int color )
void gdImageFilledArc ( gdImagePtr im, int cx, int cy, int w, int h, int s, int e, int color, int style )
void gdImageEllipse( gdImagePtr im, int mx, int my, int w, int h, int c )
void gdImageFilledEllipse ( gdImagePtr im, int mx, int my, int w, int h, int c )
void gdImageFillToBorder ( gdImagePtr im, int x, int y, int border, int color )
void gdImageFill( gdImagePtr im, int x, int y, int nc )
Draws a rectangle.
void gdImageRectangle ( gdImagePtr im, int x1, int y1, int x2, int y2, int color )
void gdImageFilledRectangle ( gdImagePtr im, int x1, int y1, int x2, int y2, int color )
Clones an image
gdImagePtr gdImageClone ( gdImagePtr src )
Copy an area of an image to another image
void gdImageCopy ( gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int w, int h )
Copy an area of an image to another image ignoring alpha
void gdImageCopyMerge ( gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int w, int h, int pct )
Copy an area of an image to another image ignoring alpha
void gdImageCopyMergeGray ( gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int w, int h, int pct )
Copy a resized area from an image to another image
void gdImageCopyResized ( gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH )
Copy a rotated area from an image to another image
void gdImageCopyRotated ( gdImagePtr dst, gdImagePtr src, double dstX, double dstY, int srcX, int srcY, int srcWidth, int srcHeight, int angle )
Copy a resampled area from an image to another image
void gdImageCopyResampled ( gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH )
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 )
Sets the style for following drawing operations
void gdImageSetStyle ( gdImagePtr im, int * style, int noOfPixels )
Sets the thickness for following drawing operations
void gdImageSetThickness ( gdImagePtr im, int thickness )
Sets the brush for following drawing operations
void gdImageSetBrush ( gdImagePtr im, gdImagePtr brush )
void gdImageSetTile ( gdImagePtr im, gdImagePtr tile )
Set the color for subsequent anti-aliased drawing
void gdImageSetAntiAliased ( gdImagePtr im, int c )
Set the color and “dont_blend” color for subsequent anti-aliased drawing
void gdImageSetAntiAliasedDontBlend ( gdImagePtr im, int c, int dont_blend )
Sets whether an image is interlaced
void gdImageInterlace ( gdImagePtr im, int interlaceArg )
Compare two images
int gdImageCompare ( gdImagePtr im1, gdImagePtr im2 )
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 )
Sets the save alpha flag
void gdImageSaveAlpha ( gdImagePtr im, int saveAlphaArg )
Sets the clipping rectangle
void gdImageSetClip ( gdImagePtr im, int x1, int y1, int x2, int y2 )
Gets the current clipping rectangle
void gdImageGetClip ( gdImagePtr im, int * x1P, int * y1P, int * x2P, int * y2P )
Sets the resolution of an image.
void gdImageSetResolution( gdImagePtr im, const unsigned int res_x, const unsigned int res_y )
Convert a palette image to true color
int gdImagePaletteToTrueColor( gdImagePtr src )
Alias of gdImageStringFT.
char * gdImageStringTTF ( gdImage * im, int * brect, int fg, const char * fontlist, double ptsize, double angle, int x, int y, const char * string )
Scale an image
gdImagePtr gdImageScale( const gdImagePtr src, const unsigned int new_width, const unsigned int new_height )
Rotate an image
gdImagePtr gdImageRotateInterpolated( const gdImagePtr src, const float angle, int bgcolor )
Converts a truecolor image to a palette image
int gdImageTrueColorToPalette ( gdImagePtr im, int dither, int colorsWanted )