Gmagick::setimageresolution()函数是PHP中的内置函数,用于设置图像对象的分辨率。
用法:
Gmagick Gmagick::setImageResolution($x_resolution, $y_resolution)
参数:该函数接受上述和以下所述的两个参数:
- $x_resolution:这是必填参数,用于指定x轴分辨率。
- $y_resolution:这是必需的参数,用于指定y轴分辨率。
返回值:成功时,此函数返回Gmagick对象。
以下示例程序旨在说明PHP中的Gmagick::setimageresolution()函数:
程序1:
原始图片:
<?php
$gmagick = new Gmagick(
'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-15.png');
// Getting Resolution of image
// using getimageresolution function
$res = $gmagick->getImageResolution();
echo "X = ".$res['x'] . "</br>";
echo "Y = ".$res['y'] . "</br>";
// Function to set image resolution
$gmagick->setimageresolution(50, 50);
echo "After Set Resolution: </br>";
// Getting Resolution of image
// using getimageresolution function
$res = $gmagick->getImageResolution();
echo "X = " . $res['x'] . "</br>";
echo "Y = " . $res['y'] . "</br>";
?>
输出:
X = 37.8 Y = 37.8 After Set Resolution: X = 50 Y = 50
程序2:
原始图片:
<?php
$string = "Computer Science portal for Geeks!";
// Creating new image of above String
// and add color and background
$im = new Gmagick();
$draw = new GmagickDraw();
// Fill the color in image
$draw->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: </br>";
// Getting Resolution of created image
// using getimageresolution function
$res = $im->getImageResolution();
echo "X = ".$res['x'] . "</br>";
echo "Y = ".$res['y'] ." </br>";
// Set image resolution (50, 50)
$im->setimageresolution(50, 50);
echo "After:</br> ";
// Getting Resolution of created image
// using getimageresolution function
$res = $im->getImageResolution();
echo "X = ".$res['x'] . "</br>";
echo "Y = ".$res['y'] ." </br>";
?>
输出:
Before: X = 0 Y = 0 After: X = 50 Y = 50
参考: http://php.net/manual/en/gmagick.setimageresolution.php
相关用法
- PHP Imagick setImageResolution()用法及代码示例
- PHP Gmagick getImageRenderingIntent()用法及代码示例
- PHP Gmagick setimageblueprimary()用法及代码示例
- PHP Gmagick edgeimage()用法及代码示例
- PHP Gmagick commentImage()用法及代码示例
- PHP Gmagick borderImage()用法及代码示例
- PHP Gmagick blurimage()用法及代码示例
- PHP Gmagick getImageDispose()用法及代码示例
- PHP Gmagick chopimage()用法及代码示例
- PHP Gmagick charcoalimage()用法及代码示例
- PHP Gmagick modulateimage()用法及代码示例
- PHP Gmagick minifyimage()用法及代码示例
- PHP Gmagick setimageprofile()用法及代码示例
- PHP Gmagick motionblurimage()用法及代码示例
- PHP Gmagick setimagefilename()用法及代码示例
注:本文由纯净天空筛选整理自R_Raj大神的英文原创作品 PHP | Gmagick setimageresolution() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。