PHP | Imagick setImageUnits() Function Last Updated : 11 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report The Imagick::setImageUnits() function is an inbuilt function in PHP which is used to set the units of resolution of a particular image.Syntax: bool Imagick::setImageUnits( $units ) Parameters: This function accepts single parameter $units which is used to specify the units to be set for image. Resolution constants: The Imagick::setImageUnits() function set the Image Units, as described below: imagick::RESOLUTION_UNDEFINED(integer), unit = 0imagick::RESOLUTION_PIXELSPERINCH(integer), unit = 1imagick::RESOLUTION_PIXELSPERCENTIMETER(integer), unit = 2 Return Value: This function returns True on success.Original Image: Below programs illustrate the Imagick::setImageUnits() function in PHP: Program 1: php <?php // PHP program to illustrate // seImageUnits function $image = new Imagick( 'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-15.png'); // Use getImageUnits function $units = $image->getImageUnits(); echo "units Before SetUnit = "; print_r($units); // set image unit = 1 $image->setImageUnits(1); // Display the output $units = $image->getImageUnits(); echo "</br>units After Set = "; print_r($units); ?> Output: units Before SetUnit = 2 units After Set = 1 Program 2: php <?php $i = new Imagick( 'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-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 are based on below resolution //0=undefined, 1=pixelsperInch, 2=PixelsPerCentimeter // checking 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 double 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 Reference: https://www.php.net/manual/en/imagick.setimageunits.php Comment More infoAdvertise with us Next Article PHP | Gmagick setimageunits() Function R R_Raj Follow Improve Article Tags : Misc Web Technologies PHP Image-Processing PHP-function PHP-Imagick +2 More Practice Tags : Misc Similar Reads 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 Pixels 1 min read PHP | Imagick setImageExtent() Function The Imagick::setImageExtent() function is an inbuilt function in PHP which is used to set the image size. This function doesn't scales the image but crops the unwanted parts. Syntax: bool Imagick::setImageExtent( int $columns, int $rows ) Parameters: This function accepts two parameters as mentioned 1 min read PHP | Imagick setImageType() Function The Imagick::setImageType() function is an inbuilt function in PHP which is used to set the image type.Syntax:Â Â bool Imagick::setImageType( int $image_type ) Parameters: This function accepts a single parameter $image_type which contains an integer value corresponding to one of IMGTYPE constants. W 1 min read PHP | Imagick setImageDispose() Function The Imagick::setImageDispose() function is an inbuilt function in PHP which is used to sets the image disposal method. Syntax: bool Imagick::setImageDispose( $dispose ) Parameters: This function accepts single parameter $dispose which specifies the dispose Imagick object to be set. Return Value: Thi 2 min read PHP | Imagick setImageOpacity() Function The Imagick::setImageOpacity() function is an inbuilt function in PHP which is used to set the opacity level of an Imagick object. This method is available in ImageMagick 6.3.1 or newer versions. Syntax: bool Imagick::setImageOpacity( $opct ) Parameters: This function accepts single parameter $opct 1 min read PHP | Imagick setImageScene() Function The Imagick::setImageScene() function is an inbuilt function in PHP which is used to set the image scene. The value of scene contains an integer value. Syntax: bool Imagick::setImageScene( int $scene ) Parameters: This function accepts a single parameter $scene which holds the scene. Return Value: T 1 min read Like