# Image Filters

Summary

Image Filters |
Functions |
gdImageScatter |
gdImageScatterColor |
gdImageScatterEx |
gdImagePixelate |
gdImageNegate | Invert an image
gdImageGrayScale | Convert an image to grayscale
gdImageBrightness | Change the brightness of an image
gdImageContrast | Change the contrast of an image
gdImageColor | Change channel values of an image
gdImageConvolution | Apply a convolution matrix to an image
gdImageSelectiveBlur |
gdImageEdgeDetectQuick | Edge detection of an image
gdImageGaussianBlur | gdImageGaussianBlur performs a Gaussian blur of radius 1 on the image.
gdImageEmboss | Emboss an image
gdImageMeanRemoval | Mean removal of an image
gdImageSmooth | Smooth an image
gdImageCopyGaussianBlurred | Return a copy of the source image src blurred according to the parameters using the Gaussian Blur algorithm.

### Functions

### gdImageScatter

> int gdImageScatter( | gdImagePtr | im,
> | int | sub,
> | int | plus | )

### gdImageScatterColor

> int gdImageScatterColor( |  | gdImagePtr | im,
> |  | int | sub,
> |  | int | plus,
> |  | int | colors[],
> | unsigned | int | num_colors | )

### gdImageScatterEx

> int gdImageScatterEx( | gdImagePtr | im,
> | gdScatterPtr | scatter | )

### gdImagePixelate

> int gdImagePixelate( |  | gdImagePtr | im,
> |  | int | block_size,
> | const unsigned | int | mode | )

### gdImageNegate

> int gdImageNegate( | gdImagePtr | src | )

Invert an image

#### Parameters

src | The image.

#### Returns

Non-zero on success, zero on failure.

### gdImageGrayScale

> int gdImageGrayScale( | gdImagePtr | src | )

Convert an image to grayscale

The red, green and blue components of each pixel are replaced by their weighted sum using the same coefficients as the REC.601 luma (Y’) calculation. The alpha components are retained.

For palette images the result may differ due to palette limitations.

#### Parameters

src | The image.

#### Returns

Non-zero on success, zero on failure.

### gdImageBrightness

> int gdImageBrightness( | gdImagePtr | src,
> | int | brightness | )

Change the brightness of an image

#### Parameters

src | The image.
brightness | The value to add to the color channels of all pixels.

#### Returns

Non-zero on success, zero on failure.

#### See also

- gdImageContrast
- gdImageColor

### gdImageContrast

> int gdImageContrast( | gdImagePtr | src,
> | double | contrast | )

Change the contrast of an image

#### Parameters

src | The image.
contrast | The contrast adjustment value. Negative values increase, postive values decrease the contrast. The larger the absolute value, the stronger the effect.

#### Returns

Non-zero on success, zero on failure.

#### See also

- gdImageBrightness

### gdImageColor

> int gdImageColor( |  | gdImagePtr | src,
> | const | int | red,
> | const | int | green,
> | const | int | blue,
> | const | int | alpha | )

Change channel values of an image

#### Parameters

src | The image.
red | The value to add to the red channel of all pixels.
green | The value to add to the green channel of all pixels.
blue | The value to add to the blue channel of all pixels.
alpha | The value to add to the alpha channel of all pixels.

#### Returns

Non-zero on success, zero on failure.

#### See also

- gdImageBrightness

### gdImageConvolution

> int gdImageConvolution( | gdImagePtr | src,
> | float | filter[3][3],
> | float | filter_div,
> | float | offset | )

Apply a convolution matrix to an image

Depending on the matrix a wide range of effects can be accomplished, e.g. blurring, sharpening, embossing and edge detection.

#### Parameters

src | The image.
filter | The 3x3 convolution matrix.
filter_div | The value to divide the convoluted channel values by.
offset | The value to add to the convoluted channel values.

#### Returns

Non-zero on success, zero on failure.

#### See also

- gdImageEdgeDetectQuick
- gdImageGaussianBlur
- gdImageEmboss
- gdImageMeanRemoval
- gdImageSmooth

### gdImageSelectiveBlur

> int gdImageSelectiveBlur( | gdImagePtr | src | )

### gdImageEdgeDetectQuick

> int gdImageEdgeDetectQuick( | gdImagePtr | src | )

Edge detection of an image

#### Parameters

src | The image.

#### Returns

Non-zero on success, zero on failure.

#### See also

- gdImageMeanRemoval
- gdImageConvolution

### gdImageGaussianBlur

> int gdImageGaussianBlur( | gdImagePtr | im | )

gdImageGaussianBlur performs a Gaussian blur of radius 1 on the image. The image is modified in place.

NOTE: You will almost certain want to use gdImageCopyGaussianBlurred instead, as it allows you to change your kernel size and sigma value. Future versions of this function may fall back to calling it instead of gdImageConvolution, causing subtle changes so be warned.

#### Parameters

im | The image to blur

#### Returns

GD_TRUE (1) on success, GD_FALSE (0) on failure.

### gdImageEmboss

> int gdImageEmboss( | gdImagePtr | im | )

Emboss an image

#### Parameters

im | The image.

#### Returns

Non-zero on success, zero on failure.

#### See also

- gdImageConvolution

### gdImageMeanRemoval

> int gdImageMeanRemoval( | gdImagePtr | im | )

Mean removal of an image

#### Parameters

im | The image.

#### Returns

Non-zero on success, zero on failure.

#### See also

- gdImageEdgeDetectQuick
- gdImageConvolution

### gdImageSmooth

> int gdImageSmooth( | gdImagePtr | im,
> | float | weight | )

Smooth an image

#### Parameters

im | The image.
weight | The strength of the smoothing.

#### Returns

Non-zero on success, zero on failure.

#### See also

- gdImageConvolution

### gdImageCopyGaussianBlurred

Return a copy of the source image src blurred according to the parameters using the Gaussian Blur algorithm.

radius is a radius, not a diameter so a radius of 2 (for example) will blur across a region 5 pixels across (2 to the center, 1 for the center itself and another 2 to the other edge).

sigma represents the “fatness” of the curve (lower == fatter). If sigma is less than or equal to 0, gdImageCopyGaussianBlurred ignores it and instead computes an “optimal” value. Be warned that future versions of this function may compute sigma differently.

The resulting image is always truecolor.

#### More Details

A Gaussian Blur is generated by replacing each pixel’s color values with the average of the surrounding pixels’ colors. This region is a circle whose radius is given by argument radius. Thus, a larger radius will yield a blurrier image.

This average is not a simple mean of the values. Instead, values are weighted using the Gaussian function (roughly a bell curve centered around the destination pixel) giving it much more influence on the result than its neighbours. Thus, a fatter curve will give the center pixel more weight and make the image less blurry; lower sigma values will yield flatter curves.

Currently, gdImageCopyGaussianBlurred computes the default sigma as

(2/3)*radius

Note, however that we reserve the right to change this if we find a better ratio. If you absolutely need the current sigma value, you should set it yourself.

#### Parameters

src | the source image
radius | the blur radius (not diameter--range is 2*radius + 1)
sigma | the sigma value or a value <= 0.0 to use the computed default

#### Returns

The new image or NULL if an error occurred. The result is always truecolor.

#### Example

>     FILE *in;
>     gdImagePtr result, src;

>     in = fopen("foo.png", "rb");
>     src = gdImageCreateFromPng(in);

>     result = gdImageCopyGaussianBlurred(im, src->sx / 10, -1.0);

> int gdImageScatter( | gdImagePtr | im,
> | int | sub,
> | int | plus | )

> int gdImageScatterColor( |  | gdImagePtr | im,
> |  | int | sub,
> |  | int | plus,
> |  | int | colors[],
> | unsigned | int | num_colors | )

> int gdImageScatterEx( | gdImagePtr | im,
> | gdScatterPtr | scatter | )

> int gdImagePixelate( |  | gdImagePtr | im,
> |  | int | block_size,
> | const unsigned | int | mode | )

> int gdImageNegate( | gdImagePtr | src | )

Invert an image

> int gdImageGrayScale( | gdImagePtr | src | )

Convert an image to grayscale

> int gdImageBrightness( | gdImagePtr | src,
> | int | brightness | )

Change the brightness of an image

> int gdImageContrast( | gdImagePtr | src,
> | double | contrast | )

Change the contrast of an image

> int gdImageColor( |  | gdImagePtr | src,
> | const | int | red,
> | const | int | green,
> | const | int | blue,
> | const | int | alpha | )

Change channel values of an image

> int gdImageConvolution( | gdImagePtr | src,
> | float | filter[3][3],
> | float | filter_div,
> | float | offset | )

Apply a convolution matrix to an image

> int gdImageSelectiveBlur( | gdImagePtr | src | )

> int gdImageEdgeDetectQuick( | gdImagePtr | src | )

Edge detection of an image

> int gdImageGaussianBlur( | gdImagePtr | im | )

gdImageGaussianBlur performs a Gaussian blur of radius 1 on the image.

> int gdImageEmboss( | gdImagePtr | im | )

Emboss an image

> int gdImageMeanRemoval( | gdImagePtr | im | )

Mean removal of an image

> int gdImageSmooth( | gdImagePtr | im,
> | float | weight | )

Smooth an image
Return a copy of the source image src blurred according to the parameters using the Gaussian Blur algorithm.
Close