PHP | Gmagick despeckleimage() Function
The Gmagick::despeckleimage() function is an inbuilt function in PHP which is used to reduce the speckle noise in an image while preserving the edges of the original image.
Syntax:
Gmagick Gmagick::despeckleimage( void )
Parameters: This function doesn’t accept any parameter.
Return Value: This function returns a Gmagick object on success.
Exceptions: This function throws GmagickException on error.
Used Image: To capture the canvas area.
Below given programs illustrate the Gmagick::despeckleimage() function in PHP:
Program 1:
<?php // Create a new Gmagick object$gmagick = new Gmagick('geeksforgeeksgnoised.png'); // Apply the despeckle function$gmagicknew = $gmagick->despeckleimage(); // Output the imageheader('Content-type: image/png');echo $gmagicknew;?> |
Output:
Program 2:
<?php // Create a new Gmagick object$gmagick = new Gmagick('./geeksforgeeksnoised.png'); // Get the image histogram$pixels = $gmagick->getimagehistogram(); echo "Color of 100th pixel before removing noise: ";echo $pixels[99]->getcolor(); // Apply the despeckle function$gmagicknew = $gmagick->despeckleimage(); // Get the image histogram$pixels = $gmagick->getimagehistogram(); echo "<br>Color of 100th pixel after removing noise: ";echo $pixels[99]->getcolor();?> |
Output:
Color of 100th pixel before removing noise: rgb(0, 6682, 8995) Color of 100th pixel after removing noise: rgb(3084, 5397, 7967)
Reference: https://www.php.net/manual/en/gmagick.despeckleimage.php


