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