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.
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);
Cropping | Crop an image |
Functions | |
gdImageCrop | Crop an image to a given rectangle |
gdImageCropAuto | Crop an image automatically |
gdImageCropThreshold | Crop an image using a given color |
gdImagePtr gdImageCrop( gdImagePtr src, const gdRect * crop )
Crop an image to a given rectangle
src | The image. |
crop | The cropping rectangle, see gdRect. |
The newly created cropped image, or NULL on failure.
gdImagePtr gdImageCropAuto( gdImagePtr im, const unsigned int mode )
Crop an image automatically
This function detects the cropping area according to the given mode.
im | The image. |
mode | The cropping mode, see gdCropMode. |
The newly created cropped image, or NULL on failure.
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.
im | The image. |
color | The crop color. |
threshold | The crop threshold. |
The newly created cropped image, or NULL on failure.
Crop an image to a given rectangle
gdImagePtr gdImageCrop( gdImagePtr src, const gdRect * crop )
Crop an image automatically
gdImagePtr gdImageCropAuto( gdImagePtr im, const unsigned int mode )
Crop an image using a given color
gdImagePtr gdImageCropThreshold( gdImagePtr im, const unsigned int color, const float threshold )