How to Create a Gaussian Blur Effect on an Image in PHP

Cloudmersive
2 min readMar 6, 2023

--

Adding image filters to your applications is easy and highly efficient with simple, value-add APIs at your disposal. With the PHP code examples provided below, you can rapidly implement our free-to-use Gaussian Blur API, enabling your application users to customize image uploads with zero extra hassle.

First, install the PHP client using composer by executing this command from the command line:

composer require cloudmersive/cloudmersive_imagerecognition_api_client

Next, use the remaining code examples to structure your API call. To make free API calls, register a free account on our website and copy & paste your API key where indicated in the $config line:

<?php
require_once(__DIR__ . '/vendor/autoload.php');

// Configure API key authorization: Apikey
$config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('Apikey', 'YOUR_API_KEY');
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
// $config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKeyPrefix('Apikey', 'Bearer');

$apiInstance = new Swagger\Client\Api\FilterApi(
// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
// This is optional, `GuzzleHttp\Client` will be used as default.
new GuzzleHttp\Client(),
$config
);
$radius = 56; // int | Radius in pixels of the blur operation; a larger radius will produce a greater blur effect
$sigma = 56; // int | Sigma, or variance, of the gaussian blur operation
$image_file = "/path/to/file.txt"; // \SplFileObject | Image file to perform the operation on. Common file formats such as PNG, JPEG are supported.

try {
$result = $apiInstance->filterGaussianBlur($radius, $sigma, $image_file);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling FilterApi->filterGaussianBlur: ', $e->getMessage(), PHP_EOL;
}
?>

In case you’re unfamiliar with what a Gaussian Blur effect does: this operation will reduce the detail in an image to a specified degree. It’s useful for a variety of scenarios, particularly when compositing images or overlaying text on top of an image. The reduction in detail draws attention to the overlayed image/text to a specific degree without eliminating the background image aesthetic in the process.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

No responses yet