PHP | Imagick setImage() Function

The Imagick::setImage() function is an inbuilt function in PHP which is used to replace an image in the object.

Syntax:

bool Imagick::setImage( Imagick $replace )

Parameters: This function accepts single parameter $replace which holds an Imagick object.

Return Value: This function returns TRUE on success.

Exceptions: This function throws ImagickException on error.

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

Program:




<?php
  
// Create two Imagick objects
$imagick_source = new Imagick(
'https://media.w3wiki.net/wp-content/uploads/20190823154611/w3wiki24.png');
  
$imagick_replace= new Imagick(
'https://media.w3wiki.net/wp-content/uploads/20190918234528/colorize1.png');
  
// Replacing w3wiki24.png with colorize1.png
$imagick_source->setImage($imagick_replace);
  
// Display the output image
header('Content-type: image/jpeg');
  
echo $imagick_source;
?>


Output:

Reference: https://www.php.net/manual/en/imagick.setimage.php