# gd.c

Summary

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

### Error Handling

### gdSetErrorMethod

> void gdSetErrorMethod( | gdErrorMethod | error_method | )

### gdClearErrorMethod

> void gdClearErrorMethod( | void | )

### Creation and Destruction

### gdImageCreate

> 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().

#### Parameters

sx | The image width.
sy | The image height.

#### Returns

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

#### Example

>     gdImagePtr im;
>     im = gdImageCreate(64, 64);
>     // ... Use the image ...
>     gdImageDestroy(im);

#### See Also

gdImageCreateTrueColor

### gdImageCreateTrueColor

> 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.

#### Parameters

sx | The image width.
sy | The image height.

#### Returns

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

#### Example

>     gdImagePtr im;
>     im = gdImageCreateTrueColor(64, 64);
>     // ... Use the image ...
>     gdImageDestroy(im);

#### See Also

gdImageCreateTrueColor

### gdImageDestroy

> 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.

#### Parameters

im | Pointer to the gdImage to delete.

#### Returns

Nothing.

#### Example

>     gdImagePtr im;
>     im = gdImageCreate(10, 10);
>     // ... Use the image ...
>     // Now destroy it
>     gdImageDestroy(im);

### Color

### gdImageColorClosest

> 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.

#### Parameters

im | The image.
r | The value of the red component.
g | The value of the green component.
b | The value of the blue component.

#### Returns

The closest color already available in the palette for palette images; the color value of the given components for truecolor images.

#### See also

- gdImageColorExact

### gdImageColorClosestAlpha

> int gdImageColorClosestAlpha ( | gdImagePtr | im,
> | int | r,
> | int | g,
> | int | b,
> | int | a | )

Gets the closest color of the image

#### Parameters

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.

#### Returns

The closest color already available in the palette for palette images; the color value of the given components for truecolor images.

#### See also

- gdImageColorExactAlpha

### gdImageColorClosestHWB

> int gdImageColorClosestHWB ( | gdImagePtr | im,
> | int | r,
> | int | g,
> | int | b | )

### gdImageColorExact

> 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.

#### Parameters

im | The image.
r | The value of the red component.
g | The value of the green component.
b | The value of the blue component.

#### Returns

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.

#### See also

- gdImageColorClosest

### gdImageColorExactAlpha

> int gdImageColorExactAlpha ( | gdImagePtr | im,
> | int | r,
> | int | g,
> | int | b,
> | int | a | )

Gets the exact color of the image

#### Parameters

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.

#### Returns

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.

#### See also

- gdImageColorClosestAlpha
- gdTrueColorAlpha

### gdImageColorAllocate

> 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.

#### Parameters

im | The image.
r | The value of the red component.
g | The value of the green component.
b | The value of the blue component.

#### Returns

The color value.

#### See also

- gdImageColorDeallocate

### gdImageColorAllocateAlpha

> 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.

#### Parameters

im | The image.
r | The value of the red component.
g | The value of the green component.
b | The value of the blue component.

#### Returns

The color value.

#### See also

- gdImageColorDeallocate

### gdImageColorResolve

> 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.

### gdImageColorResolveAlpha

> int gdImageColorResolveAlpha ( | gdImagePtr | im,
> | int | r,
> | int | g,
> | int | b,
> | int | a | )

### gdImageColorDeallocate

> void gdImageColorDeallocate ( | gdImagePtr | im,
> | int | color | )

Removes a palette entry

This is a no-op for truecolor images.

#### Parameters

im | The image.
color | The palette index.

#### See also

- gdImageColorAllocate
- gdImageColorAllocateAlpha

### gdImageColorTransparent

> void gdImageColorTransparent ( | gdImagePtr | im,
> | int | color | )

Sets the transparent color of the image

#### Parameter

im | The image.
color | The color.

#### See also

- gdImageGetTransparent

### gdImagePaletteCopy

> void gdImagePaletteCopy ( | gdImagePtr | to,
> | gdImagePtr | from | )

### gdImageColorReplace

> int gdImageColorReplace ( | gdImagePtr | im,
> | int | src,
> | int | dst | )

### gdImageColorReplaceThreshold

> int gdImageColorReplaceThreshold ( | gdImagePtr | im,
> | int | src,
> | int | dst,
> | float | threshold | )

### gdImageColorReplaceArray

> int gdImageColorReplaceArray ( | gdImagePtr |  | im,
> | int |  | len,
> | int | * | src,
> | int | * | dst | )

### gdImageColorReplaceCallback

> int gdImageColorReplaceCallback ( | gdImagePtr | im,
> | gdCallbackImageColor | callback | )

### Pixels

### gdImageSetPixel

> void gdImageSetPixel ( | gdImagePtr | im,
> | int | x,
> | int | y,
> | int | color | )

### gdImageGetPixel

> int gdImageGetPixel ( | gdImagePtr | im,
> | int | x,
> | int | y | )

Gets a pixel color as stored in the image.

#### Parameters

im | The image.
x | The x-coordinate.
y | The y-coordinate.

#### See also

- gdImageGetTrueColorPixel
- gdImagePalettePixel
- gdImageTrueColorPixel

### gdImageGetTrueColorPixel

> int gdImageGetTrueColorPixel ( | gdImagePtr | im,
> | int | x,
> | int | y | )

Gets a pixel color always as truecolor value.

#### Parameters

im | The image.
x | The x-coordinate.
y | The y-coordinate.

#### See also

- gdImageGetPixel
- gdImageTrueColorPixel

### Primitives

### gdImageAABlend

> void gdImageAABlend ( | gdImagePtr | im | )

NO-OP, kept for library compatibility.

### gdImageLine

> void gdImageLine ( | gdImagePtr | im,
> | int | x1,
> | int | y1,
> | int | x2,
> | int | y2,
> | int | color | )

Bresenham as presented in Foley & Van Dam.

### gdImageDashedLine

> void gdImageDashedLine ( | gdImagePtr | im,
> | int | x1,
> | int | y1,
> | int | x2,
> | int | y2,
> | int | color | )

### gdImageBoundsSafe

> int gdImageBoundsSafe ( | gdImagePtr | im,
> | int | x,
> | int | y | )

### gdImageChar

> void gdImageChar ( | gdImagePtr | im,
> | gdFontPtr | f,
> | int | x,
> | int | y,
> | int | c,
> | int | color | )

Draws a single character.

#### Parameters

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.
color | The color.

#### Variants

- gdImageCharUp

#### See also

- gdFontPtr

### gdImageCharUp

> void gdImageCharUp ( | gdImagePtr | im,
> | gdFontPtr | f,
> | int | x,
> | int | y,
> | int | c,
> | int | color | )

### gdImageString

> void gdImageString ( |  | gdImagePtr |  | im,
> |  | gdFontPtr |  | f,
> |  | int |  | x,
> |  | int |  | y,
> | unsigned | char | * | s,
> |  | int |  | color | )

Draws a character string.

#### Parameters

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.

#### Variants

- gdImageStringUp
- gdImageString16
- gdImageStringUp16

#### See also

- gdFontPtr
- gdImageStringTTF

### gdImageStringUp

> void gdImageStringUp ( |  | gdImagePtr |  | im,
> |  | gdFontPtr |  | f,
> |  | int |  | x,
> |  | int |  | y,
> | unsigned | char | * | s,
> |  | int |  | color | )

### gdImageString16

> void gdImageString16 ( |  | gdImagePtr |  | im,
> |  | gdFontPtr |  | f,
> |  | int |  | x,
> |  | int |  | y,
> | unsigned | short | * | s,
> |  | int |  | color | )

### gdImageStringUp16

> void gdImageStringUp16 ( |  | gdImagePtr |  | im,
> |  | gdFontPtr |  | f,
> |  | int |  | x,
> |  | int |  | y,
> | unsigned | short | * | s,
> |  | int |  | color | )

### gdImageArc

> void gdImageArc ( | gdImagePtr | im,
> | int | cx,
> | int | cy,
> | int | w,
> | int | h,
> | int | s,
> | int | e,
> | int | color | )

### gdImageFilledArc

> void gdImageFilledArc ( | gdImagePtr | im,
> | int | cx,
> | int | cy,
> | int | w,
> | int | h,
> | int | s,
> | int | e,
> | int | color,
> | int | style | )

### gdImageEllipse

> void gdImageEllipse( | gdImagePtr | im,
> | int | mx,
> | int | my,
> | int | w,
> | int | h,
> | int | c | )

### gdImageFilledEllipse

> void gdImageFilledEllipse ( | gdImagePtr | im,
> | int | mx,
> | int | my,
> | int | w,
> | int | h,
> | int | c | )

### gdImageFillToBorder

> void gdImageFillToBorder ( | gdImagePtr | im,
> | int | x,
> | int | y,
> | int | border,
> | int | color | )

### gdImageFill

> void gdImageFill( | gdImagePtr | im,
> | int | x,
> | int | y,
> | int | nc | )

### gdImageRectangle

> void gdImageRectangle ( | gdImagePtr | im,
> | int | x1,
> | int | y1,
> | int | x2,
> | int | y2,
> | int | color | )

Draws a rectangle.

#### Parameters

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.

#### See also

- gdImageFilledRectangle

### gdImageFilledRectangle

> void gdImageFilledRectangle ( | gdImagePtr | im,
> | int | x1,
> | int | y1,
> | int | x2,
> | int | y2,
> | int | color | )

### Cloning and Copying

### gdImageClone

> gdImagePtr gdImageClone ( | gdImagePtr | src | )

Clones an image

Creates an exact duplicate of the given image.

#### Parameters

src | The source image.

#### Returns

The cloned image on success, NULL on failure.

### gdImageCopy

> 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

#### Parameters

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.

#### See also

- gdImageCopyMerge
- gdImageCopyMergeGray

### gdImageCopyMerge

> 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.

#### Note

This function is a substitute for real alpha channel operations, so it doesn’t pay attention to the alpha channel.

#### Parameters

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.

#### See also

- gdImageCopy
- gdImageCopyMergeGray

### gdImageCopyMergeGray

> 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.

#### Note

This function is a substitute for real alpha channel operations, so it doesn’t pay attention to the alpha channel.

#### Parameters

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.

#### See also

- gdImageCopy
- gdImageCopyMerge

### gdImageCopyResized

> 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.

#### Parameters

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.

#### See also

- gdImageCopyResampled
- gdImageScale

### gdImageCopyRotated

> 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.

#### Parameters

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.

#### See also

- gdImageRotateInterpolated

### gdImageCopyResampled

> 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.

#### Parameters

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.

#### See also

- gdImageCopyResized
- gdImageScale

### Polygons

### gdImagePolygon

> void gdImagePolygon ( | gdImagePtr | im,
> | gdPointPtr | p,
> | int | n,
> | int | c | )

Draws a closed polygon

#### Parameters

im | The image.
p | The vertices as array of gdPoints.
n | The number of vertices.
c | The color.

#### See also

- gdImageOpenPolygon
- gdImageFilledPolygon

### gdImageOpenPolygon

> void gdImageOpenPolygon ( | gdImagePtr | im,
> | gdPointPtr | p,
> | int | n,
> | int | c | )

Draws an open polygon

#### Parameters

im | The image.
p | The vertices as array of gdPoints.
n | The number of vertices.
c | The color

#### See also

- gdImagePolygon

### gdImageFilledPolygon

> 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.

#### Parameters

im | The image.
p | The vertices as array of gdPoints.
n | The number of vertices.
c | The color

#### See also

- gdImagePolygon

### other

### gdImageSetStyle

> void gdImageSetStyle ( | gdImagePtr |  | im,
> | int | * | style,
> | int |  | noOfPixels | )

Sets the style for following drawing operations

#### Parameters

im | The image.
style | An array of color values.
noOfPixel | The number of color values.

### gdImageSetThickness

> void gdImageSetThickness ( | gdImagePtr | im,
> | int | thickness | )

Sets the thickness for following drawing operations

#### Parameters

im | The image.
thickness | The thickness in pixels.

### gdImageSetBrush

> void gdImageSetBrush ( | gdImagePtr | im,
> | gdImagePtr | brush | )

Sets the brush for following drawing operations

#### Parameters

im | The image.
brush | The brush image.

### gdImageSetTile

> void gdImageSetTile ( | gdImagePtr | im,
> | gdImagePtr | tile | )

### gdImageSetAntiAliased

> 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.

#### Example: draw an anti-aliased blue line

>     gdImageSetAntiAliased(im, gdTrueColorAlpha(0, 0, gdBlueMax, gdAlphaOpaque));
>     gdImageLine(im, 10,10, 20,20, gdAntiAliased);

#### Parameters

im | The image.
c | The color.

#### See also

- gdImageSetAntiAliasedDontBlend

### gdImageSetAntiAliasedDontBlend

> 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.

#### Parameters

im | The image.
c | The color.
dont_blend | Whether to blend.

### gdImageInterlace

> void gdImageInterlace ( | gdImagePtr | im,
> | int | interlaceArg | )

Sets whether an image is interlaced

This is relevant only when saving the image in a format that supports interlacing.

#### Parameters

im | The image.
interlaceArg | Whether the image is interlaced.

#### See also

- gdImageGetInterlaced

### gdImageCompare

> int gdImageCompare ( | gdImagePtr | im1,
> | gdImagePtr | im2 | )

Compare two images

#### Parameters

im1 | An image.
im2 | Another image.

#### Returns

A bitmask of Image Comparison flags where each set flag signals which attributes of the images are different.

### gdAlphaBlend

> int gdAlphaBlend ( | int | dst,
> | int | src | )

Blend two colors

#### Parameters

dst | The color to blend onto.
src | The color to blend.

#### See also

- gdImageAlphaBlending
- gdLayerOverlay
- gdLayerMultiply

### gdLayerOverlay

> int gdLayerOverlay ( | int | dst,
> | int | src | )

Overlay two colors

#### Parameters

dst | The color to overlay onto.
src | The color to overlay.

#### See also

- gdImageAlphaBlending
- gdAlphaBlend
- gdLayerMultiply

### gdLayerMultiply

> int gdLayerMultiply ( | int | dst,
> | int | src | )

Overlay two colors with multiply effect

#### Parameters

dst | The color to overlay onto.
src | The color to overlay.

#### See also

- gdImageAlphaBlending
- gdAlphaBlend
- gdLayerOverlay

### gdImageAlphaBlending

> void gdImageAlphaBlending ( | gdImagePtr | im,
> | int | alphaBlendingArg | )

Set the effect for subsequent drawing operations

Note that the effect is used for truecolor images only.

#### Parameters

im | The image.
alphaBlendingArg | The effect.

#### See also

- Effects

### gdImageSaveAlpha

> void gdImageSaveAlpha ( | gdImagePtr | im,
> | int | saveAlphaArg | )

Sets the save alpha flag

The save alpha flag specifies whether the alpha channel of the pixels should be saved. This is supported only for image formats that support full alpha transparency, e.g. PNG.

### gdImageSetClip

> 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.

#### Parameters

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.

#### See also

- gdImageGetClip

### gdImageGetClip

> void gdImageGetClip ( | gdImagePtr |  | im,
> | int | * | x1P,
> | int | * | y1P,
> | int | * | x2P,
> | int | * | y2P | )

Gets the current clipping rectangle

#### Parameters

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.

#### See also

- gdImageSetClip

### gdImageSetResolution

> void gdImageSetResolution( |  | gdImagePtr | im,
> | const unsigned | int | res_x,
> | const unsigned | int | res_y | )

Sets the resolution of an image.

#### Parameters

im | The image.
res_x | The horizontal resolution in DPI.
res_y | The vertical resolution in DPI.

#### See also

- gdImageResolutionX
- gdImageResolutionY

### gdImagePaletteToTrueColor

> int gdImagePaletteToTrueColor( | gdImagePtr | src | )

Convert a palette image to true color

#### Parameters

src | The image.

#### Returns

Non-zero if the conversion succeeded, zero otherwise.

#### See also

- gdImageTrueColorToPalette

> void gdSetErrorMethod( | gdErrorMethod | error_method | )

> void gdClearErrorMethod( | void | )

> gdImagePtr gdImageCreate ( | int | sx,
> | int | sy | )

gdImageCreate is called to create palette-based images, with no more than 256 colors.

> gdImagePtr gdImageCreateTrueColor ( | int | sx,
> | int | sy | )

gdImageCreateTrueColor is called to create truecolor images, with an essentially unlimited number of colors.

> void gdImageDestroy ( | gdImagePtr | im | )

gdImageDestroy is used to free the memory associated with an 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 | )

Gets the closest color of the image

> int gdImageColorClosestHWB ( | gdImagePtr | im,
> | int | r,
> | int | g,
> | int | b | )

> 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 | )

Gets the exact color of the image

> 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 | )

Allocates a color

> int gdImageColorResolve ( | gdImagePtr | im,
> | int | r,
> | int | g,
> | int | b | )

gdImageColorResolve is an alternative for the code fragment

> int gdImageColorResolveAlpha ( | gdImagePtr | im,
> | int | r,
> | int | g,
> | int | b,
> | int | a | )

> void gdImageColorDeallocate ( | gdImagePtr | im,
> | int | color | )

Removes a palette entry

> void gdImageColorTransparent ( | gdImagePtr | im,
> | int | color | )

Sets the transparent color of the image

> 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 | )

> int gdImageGetPixel ( | gdImagePtr | im,
> | int | x,
> | int | y | )

Gets a pixel color as stored in the image.

> int gdImageGetTrueColorPixel ( | gdImagePtr | im,
> | int | x,
> | int | y | )

Gets a pixel color always as truecolor value.

> void gdImageAABlend ( | gdImagePtr | im | )

NO-OP, kept for library compatibility.

> void gdImageLine ( | gdImagePtr | im,
> | int | x1,
> | int | y1,
> | int | x2,
> | int | y2,
> | int | color | )

Bresenham as presented in Foley & Van Dam.

> void gdImageDashedLine ( | gdImagePtr | im,
> | int | x1,
> | int | y1,
> | int | x2,
> | int | y2,
> | int | color | )

> int gdImageBoundsSafe ( | gdImagePtr | im,
> | int | x,
> | int | y | )

> void gdImageChar ( | gdImagePtr | im,
> | gdFontPtr | f,
> | int | x,
> | int | y,
> | int | c,
> | int | color | )

Draws a single character.

> void gdImageCharUp ( | gdImagePtr | im,
> | gdFontPtr | f,
> | int | x,
> | int | y,
> | int | c,
> | int | color | )

> void gdImageString ( |  | gdImagePtr |  | im,
> |  | gdFontPtr |  | f,
> |  | int |  | x,
> |  | int |  | y,
> | unsigned | char | * | s,
> |  | int |  | color | )

Draws a character string.

> 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 | )

> void gdImageRectangle ( | gdImagePtr | im,
> | int | x1,
> | int | y1,
> | int | x2,
> | int | y2,
> | int | color | )

Draws a rectangle.

> void gdImageFilledRectangle ( | gdImagePtr | im,
> | int | x1,
> | int | y1,
> | int | x2,
> | int | y2,
> | int | color | )

> gdImagePtr gdImageClone ( | gdImagePtr | src | )

Clones an 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

> 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 an area of an image to another image ignoring alpha

> 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

> 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

> 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

> void gdImagePolygon ( | gdImagePtr | im,
> | gdPointPtr | p,
> | int | n,
> | int | c | )

Draws a closed polygon

> void gdImageOpenPolygon ( | gdImagePtr | im,
> | gdPointPtr | p,
> | int | n,
> | int | c | )

Draws an open polygon

> void gdImageFilledPolygon ( | gdImagePtr | im,
> | gdPointPtr | p,
> | int | n,
> | int | c | )

Draws a filled polygon

> void gdImageSetStyle ( | gdImagePtr |  | im,
> | int | * | style,
> | int |  | noOfPixels | )

Sets the style for following drawing operations

> void gdImageSetThickness ( | gdImagePtr | im,
> | int | thickness | )

Sets the thickness for following drawing operations

> void gdImageSetBrush ( | gdImagePtr | im,
> | gdImagePtr | brush | )

Sets the brush for following drawing operations

> void gdImageSetTile ( | gdImagePtr | im,
> | gdImagePtr | tile | )

> void gdImageSetAntiAliased ( | gdImagePtr | im,
> | int | c | )

Set the color for subsequent anti-aliased drawing

> void gdImageSetAntiAliasedDontBlend ( | gdImagePtr | im,
> | int | c,
> | int | dont_blend | )

Set the color and “dont_blend” color for subsequent anti-aliased drawing

> void gdImageInterlace ( | gdImagePtr | im,
> | int | interlaceArg | )

Sets whether an image is interlaced

> int gdImageCompare ( | gdImagePtr | im1,
> | gdImagePtr | im2 | )

Compare two images

> int gdAlphaBlend ( | int | dst,
> | int | src | )

Blend two colors

> int gdLayerOverlay ( | int | dst,
> | int | src | )

Overlay two colors

> int gdLayerMultiply ( | int | dst,
> | int | src | )

Overlay two colors with multiply effect

> void gdImageAlphaBlending ( | gdImagePtr | im,
> | int | alphaBlendingArg | )

Set the effect for subsequent drawing operations

> void gdImageSaveAlpha ( | gdImagePtr | im,
> | int | saveAlphaArg | )

Sets the save alpha flag

> void gdImageSetClip ( | gdImagePtr | im,
> | int | x1,
> | int | y1,
> | int | x2,
> | int | y2 | )

Sets the clipping rectangle

> void gdImageGetClip ( | gdImagePtr |  | im,
> | int | * | x1P,
> | int | * | y1P,
> | int | * | x2P,
> | int | * | y2P | )

Gets the current clipping rectangle

> void gdImageSetResolution( |  | gdImagePtr | im,
> | const unsigned | int | res_x,
> | const unsigned | int | res_y | )

Sets the resolution of an image.

> int gdImagePaletteToTrueColor( | gdImagePtr | src | )

Convert a palette image to true color
The data structure in which gd stores images.
Compose a truecolor value from its components
Gets the transparent color of the image.
Gets the color of a pixel.
Gets the color of a pixel.
A font structure, containing the bitmaps of all characters in a font.

> char * gdImageStringTTF ( |  | gdImage | * | im,
> |  | int | * | brect,
> |  | int |  | fg,
> | const | char | * | fontlist,
> |  | double |  | ptsize,
> |  | double |  | angle,
> |  | int |  | x,
> |  | int |  | y,
> | const | char | * | string | )

Alias of gdImageStringFT.

> gdImagePtr gdImageScale( | const | gdImagePtr | src,
> | const unsigned | int | new_width,
> | const unsigned | int | new_height | )

Scale an image

> gdImagePtr gdImageRotateInterpolated( | const | gdImagePtr | src,
> | const | float | angle,
> |  | int | bgcolor | )

Rotate an image
draw anti aliased
Whether an image is interlaced.
The layering effect
Gets the horizontal resolution in DPI.
Gets the vertical resolution in DPI.

> int gdImageTrueColorToPalette ( | gdImagePtr | im,
> | int | dither,
> | int | colorsWanted | )

Converts a truecolor image to a palette image
Close