想象不返回图像分辨率

时间:2018-05-25 14:08:09

标签: php imagemagick imagick imagemagick-convert

for attached kind of images Imagick not returning resolution(Getting only height and width)

这是我的代码。

$image = new Imagick($tempPath);
$resolutions = $image->getImageResolution();
$imageGeometry = $image->getImageGeometry();
if ($ext == 'bmp' || $ext == 'png') {
                        $xresolution = $resolutions['x'] * 2.54;
                        $yresolution = $resolutions['y'] * 2.54;
                    } else {
                        $xresolution = $resolutions['x'];
                        $yresolution = $resolutions['y'];
                    }
$msg = array("status" => "success", "imageHeight" => $imageGeometry['height'], "imageWidth" => $imageGeometry['width'], "HorizontalResolution" => $xresolution, "VerticalResolution" => $yresolution);

1 个答案:

答案 0 :(得分:0)

我跑了这个:

#!/usr/local/bin/php -f
<?php
$image = new Imagick("thing.jpg");
$resolutions = $image->getImageResolution();
$imageGeometry = $image->getImageGeometry();
var_dump($resolutions);
var_dump($imageGeometry)
?>

得到了这个,看起来对我来说是正确的:

array(2) {
  ["x"]=>
  float(72)
  ["y"]=>
  float(72)
}
array(2) {
  ["width"]=>
  int(2362)
  ["height"]=>
  int(1476)
}

你没有说你得到了什么,也没有说出你的期望。也许检查您的软件是否已正确安装并保持最新。

Exiftool同意:

exiftool thing.jpg | more
ExifTool Version Number         : 10.80
File Name                       : thing.jpg
Directory                       : .
File Size                       : 640 kB
File Modification Date/Time     : 2018:05:25 17:11:21+01:00
File Access Date/Time           : 2018:05:25 17:11:39+01:00
File Inode Change Date/Time     : 2018:05:25 17:11:21+01:00
File Permissions                : rw-r--r--
File Type                       : JPEG
File Type Extension             : jpg
MIME Type                       : image/jpeg
JFIF Version                    : 1.01
Resolution Unit                 : inches
X Resolution                    : 72          <--- HERE
Y Resolution                    : 72          <--- HERE
Image Width                     : 2362
Image Height                    : 1476
Encoding Process                : Baseline DCT, Huffman coding
Bits Per Sample                 : 8
Color Components                : 3
Y Cb Cr Sub Sampling            : YCbCr4:2:0 (2 2)
Image Size                      : 2362x1476
Megapixels                      : 3.5
iMac:~/StackOverflow: exiftool -v3 thing.jpg | more
  ExifToolVersion = 10.80
  FileName = thing.jpg
  Directory = .
  FileSize = 655131
  FileModifyDate = 1527264681
  FileAccessDate = 1527264720
  FileInodeChangeDate = 1527264681
  FilePermissions = 33188
  FileType = JPEG
  FileTypeExtension = JPG
  MIMEType = image/jpeg
JPEG APP0 (14 bytes):
    0006: 4a 46 49 46 00 01 01 01 00 48 00 48 00 00       [JFIF.....H.H..]
  + [BinaryData directory, 9 bytes]
  | JFIFVersion = 1 1
  | - Tag 0x0000 (2 bytes, int8u[2]):
  |     000b: 01 01                                           [..]
  | ResolutionUnit = 1
  | - Tag 0x0002 (1 bytes, int8u[1]):
  |     000d: 01                                              [.]
  | XResolution = 72                         <--- HERE
  | - Tag 0x0003 (2 bytes, int16u[1]):
  |     000e: 00 48                                           [.H]
  | YResolution = 72                         <--- HERE