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()函數:
程序1:
<?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 iamge unit = 1
$image->setImageUnits(1);
// Display the output
$units = $image->getImageUnits();
echo "</br>units After Set = ";
print_r($units);
?>
輸出:
units Before SetUnit = 2 units After Set = 1
程序2:
<?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);
?>
輸出:
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.net/manual/en/imagick.setimageunits.php
相關用法
- PHP Gmagick setimageunits()用法及代碼示例
- PHP Imagick distortImage()用法及代碼示例
- PHP Imagick extentImage()用法及代碼示例
- PHP Imagick getCopyright()用法及代碼示例
- PHP Imagick despeckleImage()用法及代碼示例
- PHP Imagick readImage()用法及代碼示例
- PHP Imagick convolveImage()用法及代碼示例
- PHP Imagick readImageFile()用法及代碼示例
- PHP Imagick remapImage()用法及代碼示例
- PHP Imagick readImages()用法及代碼示例
- PHP Imagick polaroidImage()用法及代碼示例
- PHP Imagick enhanceImage()用法及代碼示例
- PHP Imagick encipherImage()用法及代碼示例
- PHP Imagick embossImage()用法及代碼示例
- PHP Imagick randomThresholdImage()用法及代碼示例
注:本文由純淨天空篩選整理自R_Raj大神的英文原創作品 PHP | Imagick setImageUnits() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。