Cover Image for Imagick::charcoalImage() in PHP
184 views

Imagick::charcoalImage() in PHP

In PHP, Imagick::charcoalImage() 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 charcoalImage() method is used to simulate a charcoal drawing effect on an image. It adds a grainy and sketchy appearance to the image, giving it a charcoal-like texture.

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

public Imagick::charcoalImage(float $radius, float $sigma)

Parameters:

  • $radius: The radius of the pixel neighborhood.
  • $sigma: The standard deviation of the Gaussian distribution used to blur the image. A higher value results in a stronger charcoal effect.

Return value:

  • Returns true on success.

Example:

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

// Apply the charcoal effect to the image
$imagick->charcoalImage(1.5, 0.5);

// 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 charcoalImage() method to apply the charcoal effect to the image with a radius of 1.5 and a sigma value of 0.5. 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