Cover Image for Imagick addNoiseImage() Function in PHP
185 views

Imagick addNoiseImage() Function in PHP

In PHP, Imagick::addNoiseImage() 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 addNoiseImage() method is used to add various types of noise to the image. Noise is a random variation of color or brightness that can give an image a more textured or grainy appearance. This function can be used to create effects such as film grain or texture in images.

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

public Imagick::addNoiseImage(int $noise_type)

Parameters:

  • $noise_type: An integer representing the type of noise to add. It can take one of the following constants:
  • Imagick::NOISE_UNIFORM: Uniform noise.
  • Imagick::NOISE_GAUSSIAN: Gaussian noise.
  • Imagick::NOISE_MULTIPLICATIVEGAUSSIAN: Multiplicative Gaussian noise.
  • Imagick::NOISE_IMPULSE: Impulse noise.
  • Imagick::NOISE_LAPLACIAN: Laplacian noise.
  • Imagick::NOISE_POISSON: Poisson noise.
  • Imagick::NOISE_RANDOM: Random noise.

Return value:

  • The method returns true on success.

Example:

Let’s see an example of how to use the addNoiseImage() method to add random noise to an image:

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

// Add random noise to the image
$imagick->addNoiseImage(Imagick::NOISE_RANDOM);

// 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 addNoiseImage() method with the constant Imagick::NOISE_RANDOM to add random noise to the image. 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