Friday, October 24, 2025
HomeLanguagesPHP | Imagick morphImages() Function

PHP | Imagick morphImages() Function

The Imagick::morphImages function is an inbuilt function in PHP that is used to morph a set of images. The image pixels and size of the image are linearly interpolated to give the appearance of metamorphosis from one image to the next. 

Syntax: 

Imagick Imagick::morphImages( $number_frames )

Parameters: This function accepts single parameter $number_frames which is used to store the number of in-between images to generate.

Return Value: This function returns new Imagick object on success.

Original Images:  



Below program illustrate the Imagick::morphImages function in PHP: 

Program:  

PHP




<?php
 
// Set of images
$images = [
    "img/neveropen.png",
    "img/charcoalImage.png",
    "img/colorMatrix.png",
    "img/adaptiveThresholdImage.png",
    "img/recolorImage.png",
];
 
// Create new Imagick object
$imagick = new \Imagick(realpath($images[count($images) - 1]));
 
foreach ($images as $image) {
    $nextImage = new \Imagick(realpath($image));
    $imagick->addImage($nextImage);
}
 
$imagick->resetIterator();
 
// Use morphImages function
$morphed = $imagick->morphImages(5);
$morphed->setImageTicksPerSecond(10);
 
header("Content-Type: image/gif");
 
// Set the image format
$morphed->setImageFormat('gif');
 
// Display the output image
echo $morphed->getImagesBlob();
?>


Output: 

Reference: http://php.net/manual/en/imagick.morphimages.php
 

RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS