📜  PHP |想象一下 setImageResolution()函数

📅  最后修改于: 2022-05-13 01:56:40.642000             🧑  作者: Mango

PHP |想象一下 setImageResolution()函数

Imagick::setImageResolution()函数是PHP中的一个内置函数,用于设置图像对象的分辨率。
句法:

bool Imagick::setImageResolution($x_resolution, $y_resolution)

参数:此函数接受上面提到的两个参数,如下所述:

  • $x_resolution:必填参数,指定x轴分辨率。
  • $y_resolution:必填参数,指定y轴分辨率。

返回值:此函数将分辨率作为数组返回。
下面的程序说明了PHP中的Imagick::setImageResolution()函数:
原图:

https://media.geeksforgeeks.org/wp-content/uploads/geeks-21.png

方案一:

php
getImageResolution();
echo "X = ".$res['x'] . "
"; echo "Y = ".$res['y'] . "
";   // Function to set image resolution $imagick->setImageResolution(50, 50);     echo "After Set Resolution:
";   // Getting Resolution of image // using getimageresolution function $res = $imagick->getImageResolution(); echo "X = " . $res['x'] . "
"; echo "Y = " . $res['y'] . "
"; ?>


php
setFillColor(new ImagickPixel('green'));
   
// Set the text font size
$draw->setFontSize(50);
   
$matrix = $im->queryFontMetrics($draw, $string);
$draw->annotation(0, 40, $string);
$im->newImage($matrix['textWidth'], $matrix['textHeight'],
         new ImagickPixel('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'] ."
"; ?>


输出:

X = 37.8
Y = 37.8
After Set Resolution:
X = 50
Y = 50

原图:

https://media.geeksforgeeks.org/wp-content/uploads/Screenshot-from-2018-10-16-23-23-54.png

方案二:

PHP

setFillColor(new ImagickPixel('green'));
   
// Set the text font size
$draw->setFontSize(50);
   
$matrix = $im->queryFontMetrics($draw, $string);
$draw->annotation(0, 40, $string);
$im->newImage($matrix['textWidth'], $matrix['textHeight'],
         new ImagickPixel('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