PHP | Gmagick setimageunits() Function

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create a new Gmagick object
$gmagick = new Gmagick('geeksforgeeks.png');
   
// Set the image units
$gmagick->setImageUnits(Gmagick::RESOLUTION_PIXELSPERCENTIMETER);
  
// Get the image units
$units = $gmagick->getimageunits();
echo $units;
?>

chevron_right


Output:

2  // Which corresponds to Gmagick::RESOLUTION_PIXELSPERCENTIMETER

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create a new Gmagick object
$gmagick = new Gmagick('geeksforgeeks.png');
   
// Set the image units
$gmagick->setImageUnits(Gmagick::RESOLUTION_PIXELSPERINCH);
  
// Display the image using new units
header("Content-Type: image/png");
echo $gmagick;
?>

chevron_right


Output:

Reference: https://www.php.net/manual/en/gmagick.setimageunits.php

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.