PHP Imagick setImageUnits () function

PHP

Syntax:
bool Imagick::setImageUnits ($units)
Parameters: This function takes one parameter, $units, which is used to specify the units to be set for the image.Resolution constants:Imagick function: : setImageUnits() sets the image units as described below:
  • imagick::RESOLUTION_UNDEFINED (integer), unit = 0
  • imagick::RESOLUTION_PIXELSPERINCH (integer) , unit = 1
  • imagick::RESOLUTION_PIXELSPERCENTIMETER (integer), unit = 2
Return value:This function returns True if successful.Original image:
The following programs illustrate the Imagick::setImageUnits()function in PHP:
Program amma 1:  
// PHP illustration program
// seImageUnits function $image = new Imagick ( ` https://media.engineerforengineer.org/wp-content/uploads/engineerforengineer-15.png ` ) ;  
// Use the getImageUnits function $units = $image -> getImageUnits(); echo "units Before SetUnit =" ; print_r ( $units );  
// set iamge unit = 1 $image -> setImageUnits (1);  
// Show output $units = $image -> getImageUnits(); echo "< / br > units After Set =" ; print_r ( $units );  
?>
Output:
units Before SetUnit = 2 units After Set = 1
Program 2: $i = new Imagick ( ` https://media.engineerforengineer.org/wp-content/uploads/engineerforengineer-15.png ` ); $r = $i -> getImageResolution(); $u = $i -> getImageUnits(); echo "print previous resolution =" ; print_r ( $r );  
// print units echo "< / br > Check units =" ; print_r ( $u );  
// for units based on resolution below
// 0 = undefined, 1 = pixel in pixels, 2 = pixelsPercenter 
// check if units = 2
// then set unit = 1 if ( $u == Imagick::RESOLUTION_PIXELSPERCENTIMETER) { $r [x] = (int) round ( $r [x] * 2); $r [y] = (int) round ( $r [y] * 2); $i -> setImageUnits (Imagick::RESOLUTION_PIXELSPERINCH); $i -> setImageResolution ( $r [x], $r [y]); // note that the number type is doubled again $r = $i -> getImageResolution(); }  
// print resolution after echo "< / br > resolution after " ; print_r ( $r ); $u = $i -> getImageUnits(); echo " < / br > units After Set = " ; print_r ( $u ); ?>
Output:
print previous resolution = Array ([x] = > 37.8 [y] = > 37.8) Check units = 2 resolution after Array ([x] = > 76 [y] = > 76) units After Set = 1
Link: http://php.net/manual /en/imagick.setimageunits.php



Get Solution for free from DataCamp guru