略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: Imagick::getImageResolution

2024-04-29

Imagick::getImageResolution

(PECL imagick 2, PECL imagick 3)

Imagick::getImageResolution获取图像的x,y轴分辨率

说明

Imagick::getImageResolution(): array

获取图像的x,y轴分辨率

返回值

返回分辨率值的数组

错误/异常

错误时抛出 ImagickException。

add a noteadd a note

User Contributed Notes 5 notes

up
5
christian at cvj dot se
8 years ago
For me getImageResolution() always returns X and Y resolution in pixels per centimeter, no matter if I set it with setImageUnits() or not.

So an easy way to convert the result from pixels per centimeter to pixels per inch is to do this:

<?php
$resource
= new Imagick($path);
$imageResolution = $resource->getImageResolution();

if (!empty(
$imageResolution['y'])) {
$imageResolution['y'] =
                           
round($imageResolution['y'] * 2.54, 2);
}

if (!empty(
$imageResolution['x'])) {
$imageResolution['x'] =
                           
round($imageResolution['x'] * 2.54, 2);
}

?>
up
2
Simon Epskamp
8 years ago
Please note that this method seems to return the image density, or DPI, not it's output resolution. If you want the output resolution, please refer to Imagick::getImageGeometry: http://www.php.net/manual/en/imagick.getimagegeometry.php

See http://www.imagemagick.org/Usage/basics/#density for more infomation on the difference.
up
1
perching_eagle at yahoo dot com
14 years ago
//location of image: c:/htdocs/rose.jpg
$path="c:/htdocs/";
$image=new Imagick($path."rose.jpg");
$array=$image->getImageResolution();
print_r($array);

result:
Array
(
    [x]=>75
    [y]=>75
)
up
-1
Shawn Pyle
11 years ago
As of the following versions, the results of this function returns the x and y resolution as floats.

desktop:~$ convert --version
Version: ImageMagick 6.6.9-1 2011-04-14 Q8 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2011 ImageMagick Studio LLC
Features: OpenMP OpenCL

desktop:~$ pecl list
Installed packages, channel pecl.php.net:
==========================
Package Version State
imagick 3.0.1   stable

desktop:~$ php --version
PHP 5.3.5 (cli) (built: Mar  1 2011 12:57:53)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
    with Xdebug v2.1.0, Copyright (c) 2002-2010, by Derick Rethans
up
-10
Alex
8 years ago
Here is simple code snippet to get image DPI:
<?php
$img
= new imagick( 'file.jpg' );
print_r($img->getImageResolution()); // Array ( [x] => 72 [y] => 72 )

?>

官方地址:https://www.php.net/manual/en/imagick.getimageresolution.php

冷却塔厂家 广告
中文GPT4.0无需注册 广告
北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3