對我來說,getImageResolution() 總是回傳每公分的像素 X 和 Y 解析度,無論我是否使用 setImageUnits() 設定它。
因此,將結果從每公分的像素轉換為每英吋的像素的簡單方法是這樣做
<?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);
}
?>