(PECL imagick 2.0.0)
Imagick::getImageResolution — Gets the image X and Y resolution
Gets the image X and Y resolution.
Returns the resolution as an array.
错误时抛出 ImagickException。
holdoffhunger at gmail dot com (2012-05-03 23:38:57)
If you're doing anything intensive with the ImageMagick class, then you're going to be working with the resolution of the image a lot. In my install of PHP v.5.2.17, this function returns incorrect values, but a replacement function is easy to write by using a combination of the getImageHeight and getImageWidth properties, like so :
<?php
// Grab Image File Data
// ---------------------------------------------
$file_to_grab_with_location = "image_workshop_directory/test.bmp";
$imagick_type = new Imagick();
// Open File
// ---------------------------------------------
$file_handle_for_viewing_image_file = fopen($file_to_grab_with_location, 'a+');
$imagick_type->readImageFile($file_handle_for_viewing_image_file);
// Create Resolution Array
// ---------------------------------------------
$imagick_type_resolution = array();
// Give Resolution Array Proper Values
// ---------------------------------------------
$imagick_type_resolution['x'] = $imagick_type->getImageWidth();
$imagick_type_resolution['y'] = $imagick_type->getImageHeight();
// Output
// ---------------------------------------------
print_r($imagick_type_resolution);
?>
Results of the Output:
Array
(
[x] => 600
[y] => 450
)
Shawn Pyle (2011-04-18 12:53:47)
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
perching_eagle at yahoo dot com (2007-10-04 18:14:32)
//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
)