The Gmagick::setimageunits() function is an inbuilt function in PHP which is used to set the units of resolution of a particular image. This function has no visual impact on the image but just changes the units of resolution which can be one of Undefinedresolution, PixelsPerInchResolution, or PixelsPerCentimeterResolution.
Syntax:
Gmagick Gmagick::setimageunits( int $resolution )
Parameters: This function accepts a single parameter $resolution which holds an integer corresponding to one of the RESOLUTION constants.
List of all RESOLUTION constants are given below:
- Gmagick::RESOLUTION_UNDEFINED (0)
- Gmagick::RESOLUTION_PIXELSPERINCH (1)
- Gmagick::RESOLUTION_PIXELSPERCENTIMETER (2)
Return Value: This function returns a Gmagick object on success.
Exceptions: This function throws GmagickException on error.
Below given programs illustrate the Gmagick::setimageunits() function in PHP:
Used Image:
Program 1:
<?php // Create a new Gmagick object $gmagick = new Gmagick( 'neveropen.png' ); // Set the image units $gmagick ->setImageUnits(Gmagick::RESOLUTION_PIXELSPERCENTIMETER); // Get the image units $units = $gmagick ->getimageunits(); echo $units ; ?> |
Output:
2 // Which corresponds to Gmagick::RESOLUTION_PIXELSPERCENTIMETER
Program 2:
<?php // Create a new Gmagick object $gmagick = new Gmagick( 'neveropen.png' ); // Set the image units $gmagick ->setImageUnits(Gmagick::RESOLUTION_PIXELSPERINCH); // Display the image using new units header( "Content-Type: image/png" ); echo $gmagick ; ?> |
Output:
Reference: https://www.php.net/manual/en/gmagick.setimageunits.php