Saturday, November 22, 2025
HomeLanguagesPHP | Gmagick despeckleimage() Function

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('neveropengnoised.png');
  
// Apply the despeckle function
$gmagicknew = $gmagick->despeckleimage();
  
// Output the image
header('Content-type: image/png');
echo $gmagicknew;
?>


Output:

Program 2:




<?php
  
// Create a new Gmagick object
$gmagick = new Gmagick('./neveropennoised.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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32407 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6784 POSTS0 COMMENTS
Nicole Veronica
11931 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11999 POSTS0 COMMENTS
Shaida Kate Naidoo
6907 POSTS0 COMMENTS
Ted Musemwa
7168 POSTS0 COMMENTS
Thapelo Manthata
6863 POSTS0 COMMENTS
Umr Jansen
6848 POSTS0 COMMENTS