PHP | Gmagick setimageresolution()函数
Gmagick::setimageresolution()函数是PHP中的一个内置函数,用于设置图像对象的分辨率。
句法:
Gmagick Gmagick::setImageResolution($x_resolution, $y_resolution)
参数:此函数接受上面提到的两个参数,如下所述:
- $x_resolution:必填参数,指定x轴分辨率。
- $y_resolution:必填参数,指定y轴分辨率。
返回值:此函数在成功时返回 Gmagick 对象。
下面的程序说明了PHP中的Gmagick::setimageresolution()函数:
方案一:
原图:
getImageResolution();
echo "X = ".$res['x'] . "";
echo "Y = ".$res['y'] . "";
// Function to set image resolution
$gmagick->setimageresolution(50, 50);
echo "After Set Resolution: ";
// Getting Resolution of image
// using getimageresolution function
$res = $gmagick->getImageResolution();
echo "X = " . $res['x'] . "";
echo "Y = " . $res['y'] . "";
?>
输出:
X = 37.8
Y = 37.8
After Set Resolution:
X = 50
Y = 50
方案二:
原图:
setFillColor(new GmagickPixel('green'));
// Set the text font size
$draw->setFontSize(50);
$metrix = $im->queryFontMetrics($draw, $string);
$draw->annotation(0, 40, $string);
$im->newImage($metrix['textWidth'], $metrix['textHeight'],
new GmagickPixel('white'));
// Draw the image
$im->drawImage($draw);
echo "Before: ";
// Getting Resolution of created image
// using getimageresolution function
$res = $im->getImageResolution();
echo "X = ".$res['x'] . "";
echo "Y = ".$res['y'] ." ";
// Set image resolution (50, 50)
$im->setimageresolution(50, 50);
echo "After: ";
// Getting Resolution of created image
// using getimageresolution function
$res = $im->getImageResolution();
echo "X = ".$res['x'] . "";
echo "Y = ".$res['y'] ." ";
?>
输出:
Before:
X = 0
Y = 0
After:
X = 50
Y = 50
参考: http: PHP。 PHP