Cover Image for Imagick adaptiveBlurImage() Function in PHP
209 views

Imagick adaptiveBlurImage() Function in PHP

In PHP, Imagick::adaptiveBlurImage() is a method of the Imagick class, which is part of the Imagick extension. The Imagick extension is a powerful PHP library that allows you to manipulate images using the ImageMagick software.

The adaptiveBlurImage() method is used to apply an adaptive blur effect to the image. Unlike a regular blur, where all parts of the image are equally blurred, adaptive blur adapts the blur radius based on the local contrast of the image. This results in a blur that varies across different regions of the image, preserving edges and details.

Here’s the syntax of the adaptiveBlurImage() method:

public Imagick::adaptiveBlurImage(float $radius, float $sigma[, int $channel = Imagick::CHANNEL_DEFAULT])

Parameters:

  • $radius: The radius of the adaptive blur. A higher value produces a stronger blur effect.
  • $sigma: The standard deviation of the Gaussian distribution used for the blur. A higher value results in a smoother blur.
  • $channel: (Optional) The channel to apply the adaptive blur. It is represented by one of the Imagick::CHANNEL_* constants. By default, Imagick::CHANNEL_DEFAULT is used, which applies the blur to all channels.

Return value:

  • Returns true on success.

Example:

// Create a new Imagick object and read an image file
$imagick = new Imagick('input.jpg');

// Apply adaptive blur to the image
$imagick->adaptiveBlurImage(5, 2);

// Set the output image format to JPEG
$imagick->setImageFormat('jpeg');

// Output the modified image to the browser
header('Content-Type: image/jpeg');
echo $imagick;

In this example, we create an Imagick object and load an image file named input.jpg. Then, we use the adaptiveBlurImage() method to apply the adaptive blur effect to the image with a radius of 5 and a sigma value of 2. Finally, we set the image format to JPEG and output the modified image to the browser.

Please note that to use the Imagick class and its methods, you need to have the Imagick extension installed and enabled on your PHP server. Additionally, you should have the ImageMagick software installed on the server for the Imagick extension to work properly.

YOU MAY ALSO LIKE...

The Tech Thunder

The Tech Thunder

The Tech Thunder


COMMENTS