PHP | Imagick averageImages() Function

The Imagick::averageImages() function is an inbuilt function in PHP which is used to create an average of two or more images after image processing. It is well defined in PECL imagick 2.0.0 version. This function has been depreciated in further versions of Imagick hence it is replaced by Imagick::mergeImageLayers() in PECL imagick 2.1.0 version.


Imagick Imagick::averageImages( void )

Return Value: This function returns a new imagick object on success.

Errors/Exceptions: It throws ImagickException while error occured.

Below program illustrates the Imagick::averageImages() function in PHP:






// Store the path of an image into variable
$imagePath =
// Create a new Imagick object
$imagick = new \Imagick($imagePath);
// Create a new ImagickDraw object
$draw = new \ImagickDraw();
// Draw an image and set its font size
// Set the color of text
$fillcolor = new \ImagickPixel("red");
// Set the fill color
// Set the gravity
// Annotate the text "GeeksforGeeks" to the image
$imagick->annotateImage( $draw, 0, 0, 0, "GeeksforGeeks");
// Assign thresholdcolor to the image 
$thresholdColor = "rgb(255, 0, 0)";
// Flop the image
// Turn image to oil paint image
// Merging all image layers and flattened
// It works in PECL imagick 2.0.0 version,
// comment it when higher version.
header("Content-Type: image/png");
header("Cache-Control: no-store, no-cache");  
// Downloading output image of 
// Imagick::averageImage() function
header('Content-Disposition: attachment; filename="average.png"');
echo $imagick->getImageBlob();




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at to report any issue with the above content.