PHP |想象一下 setImageUnits()函数
Imagick::setImageUnits()函数是PHP中的一个内置函数,用于设置特定图像的分辨率单位。
句法:
bool Imagick::setImageUnits( $units )
参数:此函数接受单个参数$units ,用于指定要为图像设置的单位。
分辨率常量: Imagick::setImageUnits()函数设置图像单位,如下所述:
- imagick::RESOLUTION_UNDEFINED(整数),单位 = 0
- imagick::RESOLUTION_PIXELSPERINCH(整数),单位 = 1
- imagick::RESOLUTION_PIXELSPERCENTIMETER(整数),单位 = 2
返回值:此函数在成功时返回 True。
原图:
下面的程序说明了PHP中的Imagick::setImageUnits()函数:
方案一:
php
getImageUnits();
echo "units Before SetUnit = ";
print_r($units);
// set image unit = 1
$image->setImageUnits(1);
// Display the output
$units = $image->getImageUnits();
echo "units After Set = ";
print_r($units);
?>
php
getImageResolution();
$u = $i->getImageUnits();
echo "print previous resolution = ";
print_r($r);
// print units
echo "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 "resolution after ";
print_r($r);
$u = $i->getImageUnits();
echo "units After Set = ";
print_r($u);
?>
输出:
units Before SetUnit = 2
units After Set = 1
方案二:
PHP
getImageResolution();
$u = $i->getImageUnits();
echo "print previous resolution = ";
print_r($r);
// print units
echo "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 "resolution after ";
print_r($r);
$u = $i->getImageUnits();
echo "units After Set = ";
print_r($u);
?>
输出:
print previous resolution = Array ( [x] => 37.8 [y] => 37.8 )
Check units = 2
resolution after Array ( [x] => 76 [y] => 76 )
units After Set = 1
参考: http: PHP。 PHP