使用PHP GD / Imagick获取/设置DPI? [英] Get/set DPI with PHP GD/Imagick?

查看:134
本文介绍了使用PHP GD / Imagick获取/设置DPI?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个Web应用程序,它将处理最终将被打印的图像文件,大格式。

I'm building a Web application that will handle image files that will ultimately be printed, large format.

作为其中的一部分,我需要得到(即读取)并设置(即更改)图像文件的DPI。

As part of this, I need to get (i.e. read) and set (i.e. change) the DPI of an image file.

这可以通过PHP GD或PHP Imagick实现吗?

Is this possible through PHP GD or PHP Imagick?

谢谢,

BK

可以通过iMagick的 getImageResolution 方法访问图像的DPI:

The DPI of a image can be accessed through iMagick's getImageResolution method:

public function getDPI() {

    $imgDPI = $this->image->getImageResolution();
    return $imgDPI;

}

图像的DPI可以通过iMagick设置 setImageResolution 方法:

and the DPI of an image can be set through iMagick's setImageResolution method:

public function setDPI($DPIX, $DPIY) {

    $this->image->setImageResolution($DPIX,$DPIY);

}


推荐答案

按顺序使用getImageResolution();你必须确定PixelsPerInch中的分辨率...有时它可以是PixelsPerCentimeter

in order to use "getImageResolution();" you must be sure that resolution in "PixelsPerInch"...sometimes it can be "PixelsPerCentimeter"

使用以下代码来获取图像信息:

use following code to get image info:

$imagick = new Imagick($filename);
$data = $imagick->identifyimage();
var_dump($data);

结果(当PixelsPerInch时):

result (when PixelsPerInch):

array(11) {
              ["imageName"]=> string(11) "/jpg300.jpg"
              ["format"]=> string(51) "JPEG (Joint Photographic Experts Group JFIF format)"
              ["units"]=> string(13) "PixelsPerInch"
              ["type"]=> string(9) "TrueColor"
              ["colorSpace"]=> string(3) "RGB"
              ["compression"] => string(4) "JPEG"
              ["fileSize"] => string(6) "8.72mb"
              ["mimetype"] => string(10) "image/jpeg"
              ["geometry"] => array(2) {
                        ["width"]  => int(11812)
                        ["height"] => int(7876)
              }
              ["resolution"]=> array(2) {
                    ["x"]=> float(300)
                    ["y"]=> float(300)
              }
              ["signature"]=> string(64) "7fc387ea465ec716e9fd6e233bb1d3740cb509f5667ed2a4df0199e6e664590e"
            }

或(当PixelsPerCentimeter时):

or (when PixelsPerCentimeter):

    array(11) {
      ["imageName"]=> string(8) "/psm.jpg"
      ["format"]=> string(51) "JPEG (Joint Photographic Experts Group JFIF format)"
      ["units"]=> string(19) "PixelsPerCentimeter"
      ["type"]=> string(9) "TrueColor"
      ["colorSpace"]=> string(3) "RGB"
      ["compression"]=> string(4) "JPEG"
      ["fileSize"]=> string(7) "25.01mb"
      ["mimetype"]=> string(10) "image/jpeg"
      ["geometry"]=>
      array(2) {
        ["width"]=> int(11812)
        ["height"]=> int(7876)
      }
      ["resolution"]=>
      array(2) {
        ["x"]=> float(118.11)
        ["y"]=> float(118.11)
      }
      ["signature"]=> string(64) "b491e059624e79a4dee62d9cc7646019927b2222bfed9ac8dd4342185e648eaf"
    }

这篇关于使用PHP GD / Imagick获取/设置DPI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆