PHP | Imagick setImageUnits() Function Last Updated : 03 Mar, 2021 Comments Improve Suggest changes 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: http://php.net/manual/en/imagick.setimageunits.php Comment More infoAdvertise with us Next Article PHP | Imagick 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 PHP | Imagick setImageDepth() Function The Imagick::setImageDepth() function is an inbuilt function in PHP which is used to set the depth of a particular image.Syntax:Â Â bool Imagick::setImageDepth( $depth ) Parameters: This function accepts a single parameter $depth which is an integer value and used to set the depth of image.Return Val 2 min read PHP | Imagick setImageFormat() Function The Imagick::setImageFormat() function is an inbuilt function in PHP which is used to set the format of a particular image in a sequence.Syntax:Â Â bool Imagick::setImageFormat( string $format ) Parameters: This function accepts a single parameter $format which holds a string value of the image forma 1 min read PHP | Imagick setImagePage() Function The Imagick::setImagePage() function is an inbuilt function in PHP which is used to set the image page geometry. Syntax: bool Imagick::setImagePage(int $width, int $height, int $x, int $y ) Parameters: This function accepts four parameters as mentioned above and described below: $width: It specifies 1 min read PHP | Imagick setImageArtifact() Function The Imagick::setImageArtifact() function is an inbuilt function in PHP which is used to set the image artifact. The main difference between image properties and image artifacts is that the properties are public whereas artifacts are private. Syntax: bool Imagick::setImageArtifact( string $artifact, 1 min read Like