# 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

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

### Functions

### gdImageCrop

> gdImagePtr gdImageCrop( |  | gdImagePtr |  | src,
> | const | gdRect | * | crop | )

Crop an image to a given rectangle

#### Parameters

src | The image.
crop | The cropping rectangle, see gdRect.

#### Returns

The newly created cropped image, or NULL on failure.

#### See also

- gdImageCropAuto
- gdImageCropThreshold

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

im | The image.
mode | The cropping mode, see gdCropMode.

#### Returns

The newly created cropped image, or NULL on failure.

#### See also

- gdImageCrop
- gdImageCropThreshold

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

im | The image.
color | The crop color.
threshold | The crop threshold.

#### Returns

The newly created cropped image, or NULL on failure.

#### See also

- gdImageCrop
- gdImageCropAuto

> 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