PHP Gmagick setimageresolution () Function

PHP

Syntax:
Gmagick Gmagick::setImageResolution ($x_resolution, $y_resolution)
Parameters:This function takes two parameters as above and described below:
  • $x_resolution: Requiredparameter that specifies the resolution on the X axis.
  • $y_resolution:this is a required parameter that defines the Y-axis resolution.
Return value:This function returns an object Gmagick on success.The following program illustrates the Gmagick::setimageresolution() functionin PHP:Program 1:
Original image:
$gmagick = new Gmagick ( ' https://media.engineerforengineer.org/wp-content/uploads/engineerforengineer-15.png ' );  
// Get image resolution
// using the getimageresolution function $res = $gmagick -> getImageResolution(); echo "X =" . $res [ 'x' ]. "< / br >" ; echo "Y =" . $res [ 'y' ]. "< / br >" ;  
// Function for setting image resolution $gmagick -> setimageresolution (50, 50); echo "After Set Resolution: < / br >" ;  
// Get image resolution
// using the getimageresolution function $res = $gmagick -> getImageResolution(); echo "X =" . $res [ 'x' ]. "< / br >" ; echo "Y =" . $res [ 'y' ]. "< / br >" ; ?>
Output:
X = 37.8 Y = 37.8 After Set Resolution: X = 50 Y = 50
Program 2:
Original Image:
$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 ); echo "Before: < / br >" ;  
// Get permission for the generated image
// using the getimageresolution function $res = $im -> getImageResolution(); echo "X =" . $res [ 'x' ]. "< / br >" ; echo "Y =" . $res [ 'y' ]. " < / br > " ;  
// Set image resolution (50, 50) $im -> setimageresolution (50, 50); echo " After: < / br > " ;  
// Get permission for the generated image
// using the getimageresolution function $res = $im -> getImageResolution(); echo "X =" . $res [ 'x' ]. "< / br >" ; echo "Y =" . $res [ 'y' ]. " < / br > " ; ?>
Output:
Before: X = 0 Y = 0 After: X = 50 Y = 50
Link: http://php.net/manual/en/gmagick.setimageresolution.php



Get Solution for free from DataCamp guru