You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Imagick无法返回特定图片分辨率,仅能获取宽高问题求助

我碰到一个情况:针对特定附件类型的图片,Imagick没办法返回分辨率信息,只能获取到图片的高度和宽度。下面是我写的实现代码:

$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
);

代码里的逻辑是这样的:先通过Imagick实例获取图片的分辨率数据和几何尺寸,针对BMP、PNG格式做了特殊处理——把分辨率数值乘以2.54转换单位,其他格式直接使用获取到的原始分辨率值,最后把所有需要的信息打包成数组返回。

内容的提问来源于stack exchange,提问作者Vasantha Kumar Boddu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 06:43:27