Monday, January 19, 2026
HomeLanguagesPHP | Imagick setResolution() Function

PHP | Imagick setResolution() Function

The Imagick::setResolution() function is an inbuilt function in PHP which is used to set the resolution for image. This function doesn’t changes the actual resolution of a image but just sets it in the Imagick object before image is read or created, for changing image resolution use setImageResolution() function. This function needs to be called before reading image or creating it.

Syntax:

bool Imagick::setResolution( float $x_resolution, float $y_resolution )

Parameters: This function accepts two parameters as mentioned above and described below:

  • $x_resolution: It specifies the horizontal resolution.
  • $y_resolution: It specifies the vertical resolution.

Return Value: This function returns TRUE on success.

Exceptions: This function throws ImagickException on error.

Below programs illustrate the Imagick::setResolution() function in PHP:

Program 1:




<?php
  
// Create a new imagick object
$imagick = new Imagick();
  
// Set the resolution
$imagick->setResolution(18, 13);
  
// Create new image
$imagick->newimage(100, 100, 'none');   
  
// Read the properties of image
print("<pre>".print_r($imagick->identifyImage(), true)."</pre>");
?>


Output:

Array
(
[imageName] =>
[mimetype] => image/x-
[units] => Undefined
[type] => Bilevel
[colorSpace] => sRGB
[compression] => Undefined
[fileSize] => 0B
[geometry] => Array
(
[width] => 100
[height] => 100
)
// you can see the temporary resolution here
[resolution] => Array
(
[x] => 18
[y] => 13
)

[signature] => e7e2dcff542de95352682dc186432e98f0188084896773f1973276b0577d5305
)

Program 2:




<?php
  
// Create a new imagick object
$imagick = new Imagick();
  
// Set the resolution
$imagick->setResolution(10, 10);
  
// Read the image
$imagick->readimage(
  
// Read the properties of image
print("<pre>".print_r($imagick->identifyImage(), true)."</pre>");
?>


Output:
Array
(
[imageName] =>
[mimetype] => image/png
[format] => PNG (Portable Network Graphics)
[units] => PixelsPerCentimeter
[type] => TrueColorAlpha
[colorSpace] => sRGB
[compression] => Zip
[fileSize] => 45.4KB
[geometry] => Array
(
[width] => 667
[height] => 184
)
// Here resolution is changed because new image is read
[resolution] => Array
(
[x] => 37.8
[y] => 37.8
)

[signature] => f64054f5bcb4cfb82c6126eff6d3d4e6be7d0e72d5620033442cecb4b9feabbd
)

Reference: https://www.php.net/manual/en/imagick.setresolution.php

RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32474 POSTS0 COMMENTS
Milvus
118 POSTS0 COMMENTS
Nango Kala
6846 POSTS0 COMMENTS
Nicole Veronica
11977 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12063 POSTS0 COMMENTS
Shaida Kate Naidoo
6986 POSTS0 COMMENTS
Ted Musemwa
7219 POSTS0 COMMENTS
Thapelo Manthata
6933 POSTS0 COMMENTS
Umr Jansen
6911 POSTS0 COMMENTS