Get/set DPI with PHP GD/Imagick?

前端 未结 3 1105
执笔经年
执笔经年 2020-12-03 17:50

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

As part of this, I need to get (i.e. read) and set (i.e.

3条回答
  •  眼角桃花
    2020-12-03 18:24

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

    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"
                }
    

    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"
        }
    

提交回复
热议问题