PHP | Gmagick setimageunits() Function
Last Updated :
23 Jul, 2021
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
$gmagick = new Gmagick( 'geeksforgeeks.png' );
$gmagick ->setImageUnits(Gmagick::RESOLUTION_PIXELSPERCENTIMETER);
$units = $gmagick ->getimageunits();
echo $units ;
?>
|
Output:
2 // Which corresponds to Gmagick::RESOLUTION_PIXELSPERCENTIMETER
Program 2:
<?php
$gmagick = new Gmagick( 'geeksforgeeks.png' );
$gmagick ->setImageUnits(Gmagick::RESOLUTION_PIXELSPERINCH);
header( "Content-Type: image/png" );
echo $gmagick ;
?>
|
Output:
Reference: https://www.php.net/manual/en/gmagick.setimageunits.php
Share your thoughts in the comments
Please Login to comment...