Current Location: Home> Latest Articles> PHP Image Blur Processing Tutorial: Achieving Gaussian Blur Effect

PHP Image Blur Processing Tutorial: Achieving Gaussian Blur Effect

M66 2025-07-12

How to Use PHP to Apply Blur to Images

Image blur processing is a common technique in image manipulation, adding a soft, artistic effect to the image. With PHP's GD library, developers can easily implement this effect. In this article, we will explain how to use PHP to apply a blur effect to an image and provide code samples to help you quickly master this technique.

Installing the GD Library

Before we begin, make sure that the GD library is installed in your PHP environment. You can check whether GD is installed by using the `phpinfo()` function in a PHP file. If it's not installed, you'll need to install it manually.

Creating the Blur Function

Before applying the blur effect, we need to create a function to process the image. Below is a basic example of a blur function, which you can modify as needed:

function blurImage($source, $radius = 10, $sigma = 10) {

In the function above, we use `imagecreatefromjpeg()` to create an image resource, then apply the Gaussian blur effect using the `imagefilter()` function. Finally, the `imagejpeg()` function is used to save the processed image, with the blur intensity specified by the `$sigma` value. We also use `imagedestroy()` to free up the image resource from memory.

Usage Example

Here’s a simple example demonstrating how to apply the blur effect by calling the blur function:

$source = 'image.jpg';

In this example, we assume the image file is named `image.jpg` and apply a blur effect with a radius of 10 and a sigma of 10. You can modify these parameters as needed.

Things to Keep in Mind

When performing image blur processing, keep the following points in mind:

  • Ensure that the image path and filename are correct, and that PHP has sufficient permissions to read and write the image.
  • If the image is in PNG format or another format, use `imagecreatefrompng()` or the corresponding function to create the image resource.
  • Adjust the blur radius and sigma to control the intensity of the blur effect. You can fine-tune these parameters to achieve the desired result.

Conclusion

By using PHP's GD library, you can easily apply a blur effect to an image, creating an artistic effect. This article provides a basic implementation and code examples, which we hope will help you quickly achieve image blur processing.