gd_filter.c

Summary
gd_filter.c
Functions
gdImageGaussianBlurgdImageGaussianBlur performs a Gaussian blur of radius 1 on the image.
gdImageCopyGaussianBlurredReturn a copy of the source image src blurred according to the parameters using the Gaussian Blur algorithm.

Functions

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

imThe image to blur

Returns

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

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

srcthe source image
radiusthe blur radius (not diameter--range is 2*radius + 1)
sigmathe 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 gdImageGaussianBlur(gdImagePtr im)
gdImageGaussianBlur performs a Gaussian blur of radius 1 on the image.
Return a copy of the source image src blurred according to the parameters using the Gaussian Blur algorithm.
Close