PHP | Imagick setImageUnits() Function
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 = 0
- imagick::RESOLUTION_PIXELSPERINCH(integer), unit = 1
- imagick::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
$image = new Imagick(
$units = $image ->getImageUnits();
echo "units Before SetUnit = " ;
print_r( $units );
$image ->setImageUnits(1);
$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(
$r = $i ->getImageResolution();
$u = $i ->getImageUnits();
echo "print previous resolution = " ;
print_r( $r );
echo "</br>Check units = " ;
print_r( $u );
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]);
$r = $i ->getImageResolution();
}
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
Last Updated :
03 Mar, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...