Thursday, February 19, 2026
HomeLanguagesPHP | Gmagick setimageunits() Function

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:




<?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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32506 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6882 POSTS0 COMMENTS
Nicole Veronica
12005 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12099 POSTS0 COMMENTS
Shaida Kate Naidoo
7011 POSTS0 COMMENTS
Ted Musemwa
7255 POSTS0 COMMENTS
Thapelo Manthata
6967 POSTS0 COMMENTS
Umr Jansen
6956 POSTS0 COMMENTS