PHP |想象一下 setResolution()函数
Imagick::setResolution()函数是PHP中的一个内置函数,用于设置图像的分辨率。此函数不会更改图像的实际分辨率,而只是在读取或创建图像之前将其设置在 Imagick 对象中,要更改图像分辨率,请使用 setImageResolution()函数。在读取图像或创建图像之前需要调用此函数。
句法:
bool Imagick::setResolution( float $x_resolution, float $y_resolution )
参数:该函数接受上面提到的两个参数,如下所述:
- $x_resolution:指定水平分辨率。
- $y_resolution:指定垂直分辨率。
返回值:此函数在成功时返回 TRUE。
异常:此函数在出错时抛出 ImagickException。
下面的程序说明了PHP中的Imagick::setResolution()函数:
方案一:
setResolution(18, 13);
// Create new image
$imagick->newimage(100, 100, 'none');
// Read the properties of image
print("".print_r($imagick->identifyImage(), true)."
");
?>
输出:
Array
(
[imageName] =>
[mimetype] => image/x-
[units] => Undefined
[type] => Bilevel
[colorSpace] => sRGB
[compression] => Undefined
[fileSize] => 0B
[geometry] => Array
(
[width] => 100
[height] => 100
)
// you can see the temporary resolution here
[resolution] => Array
(
[x] => 18
[y] => 13
)
[signature] => e7e2dcff542de95352682dc186432e98f0188084896773f1973276b0577d5305
)
方案二:
setResolution(10, 10);
// Read the image
$imagick->readimage(
'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png');
// Read the properties of image
print("".print_r($imagick->identifyImage(), true)."
");
?>
Output:
Array
(
[imageName] =>
[mimetype] => image/png
[format] => PNG (Portable Network Graphics)
[units] => PixelsPerCentimeter
[type] => TrueColorAlpha
[colorSpace] => sRGB
[compression] => Zip
[fileSize] => 45.4KB
[geometry] => Array
(
[width] => 667
[height] => 184
)
// Here resolution is changed because new image is read
[resolution] => Array
(
[x] => 37.8
[y] => 37.8
)
[signature] => f64054f5bcb4cfb82c6126eff6d3d4e6be7d0e72d5620033442cecb4b9feabbd
)
参考: https://www. PHP.net/manual/en/imagick.setresolution。 PHP