(PECL imagick 2.0.0)

Imagick::getImageResolutionGets the image X and Y resolution


array Imagick::getImageResolution ( void )

Gets the image X and Y resolution.

Возвращаемые значения

Returns the resolution as an array.


Вызывает ImagickException при ошибке.


//location of image: c:/htdocs/rose.jpg
$image=new Imagick($path."rose.jpg");

2007-10-04 21:14:32
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
Copyright: Copyright (C) 1999-2011 ImageMagick Studio LLC
Features: OpenMP OpenCL 

desktop:~$ pecl list
Installed packages, channel
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
2011-04-18 15:53:47
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: imagick.getimagegeometry

See for more infomation on the difference.
2013-09-20 11:30:40
Here is simple code snippet to get image DPI:
= new imagick'file.jpg' );
print_r($img->getImageResolution()); // Array ( [x] => 72 [y] => 72 )

2013-09-27 13:00:51
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:

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

if (!empty(
$imageResolution['y'])) { 
$imageResolution['y'] = 
round($imageResolution['y'] * 2.542);

if (!empty(
$imageResolution['x'])) {
$imageResolution['x'] = 
round($imageResolution['x'] * 2.542);

2014-02-21 01:48:18

    Поддержать сайт на родительском проекте КГБ