Cropping

Crop an image

Some functions to crop images, automatically (auto detection of the border color), using a given color (with or without tolerance) or using a given rectangle.

Example

im2 = gdImageAutoCrop(im, GD_CROP_SIDES);
if (im2) {
    gdImageDestroy(im); // unless you need the original image subsequently
    // do something with the cropped image
}
gdImageDestroy(im2);
Summary
CroppingCrop an image
Functions
gdImageCropCrop an image to a given rectangle
gdImageCropAutoCrop an image automatically
gdImageCropThresholdCrop an image using a given color

Functions

gdImageCrop

gdImagePtr gdImageCrop(gdImagePtr src,
const gdRect *crop)

Crop an image to a given rectangle

Parameters

srcThe image.
cropThe cropping rectangle, see gdRect.

Returns

The newly created cropped image, or NULL on failure.

See also

gdImageCropAuto

gdImagePtr gdImageCropAuto(gdImagePtr im,
const unsigned int mode)

Crop an image automatically

This function detects the cropping area according to the given mode.

Parameters

imThe image.
modeThe cropping mode, see gdCropMode.

Returns

The newly created cropped image, or NULL on failure.

See also

gdImageCropThreshold

gdImagePtr gdImageCropThreshold(gdImagePtr im,
const unsigned int color,
const float threshold)

Crop an image using a given color

The threshold defines the tolerance to be used while comparing the image color and the color to crop.  The method used to calculate the color difference is based on the color distance in the RGB(A) cube.

Parameters

imThe image.
colorThe crop color.
thresholdThe crop threshold.

Returns

The newly created cropped image, or NULL on failure.

See also

gdImagePtr gdImageCrop(gdImagePtr src,
const gdRect *crop)
Crop an image to a given rectangle
gdImagePtr gdImageCropAuto(gdImagePtr im,
const unsigned int mode)
Crop an image automatically
gdImagePtr gdImageCropThreshold(gdImagePtr im,
const unsigned int color,
const float threshold)
Crop an image using a given color
A rectangle in the coordinate space of the image
Close