+

PHP Gmagick addImage () Function

Syntax:
bool Gmagick::addImage ($source)
Parameters: This function takes one parameter, $source, which contains the original Gmagick object.Return Value:This function returns a Gmagick object on success. Errors / Exceptions:this function throws a GmagickException on error.The following programs illustrate the Gmagick::addImage() functionin PHP:Original Image 1:
Program :  
// require_once (` path / to / vendor / autoload.php `); header ( `Content-type: image / png` ); $image = new Gmagick ( ` https://media.engineerforengineer.org/ wp-content / uploads / engineerforengineer-9.png ` ); $t = new Gmagick ( ` https://media.engineerforengineer.org/wp- content / uploads / adaptiveThresholdImage.png ` ); $image -> addImage ( $t ); echo $image ; ?>
Output:
Original Image 2:
Program 2: $string = "Computer Science portal for Geeks!" ;  
// Create a new image of the above line // and add color and background $im = new Gmagick(); $draw = new GmagickDraw();  
// Fill the color in the image $draw -> setFillColor ( new GmagickPixel ( `green` ));  
// Set the text font size $draw -> setFontSize (50); $metrix = $im -> queryFontMetrics ( $draw , $string ); $draw -> annotation (0, 40, $string ); $im -> newImage ( $metrix [ `textWidth` ], $metrix [ `textHeight` ], new GmagickPixel ( `white` ));  
// Draw image $im -> drawImage ( $draw ); $im -> setImageFormat ( `jpeg` ); $t = new Gmagick ( ` https://media.engineerforengineer.org/ wp-content / uploads / engineerforengineer-9.png ` ); $im -> addImage ( $t ); header ( "Content-Type: image / jpg" ); echo $im -> getImageBlob(); ?>
Output: Link: http://php.net/manual/en/gmagick.addimage.php
Get Solution for free from DataCamp guru