Get/set DPI with PHP GD/Imagick?

前端 未结 3 1099
执笔经年
执笔经年 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:17

    This is my work solution at Joox.io

    /**
     * @param $filename
     * @return array
     */
    function getImageDPI($filename)
    {
        $resolutions = null;
    
        if (class_exists('Imagick')) {
    
            $image = new Imagick($filename);
            $resolutions = $image->getImageResolution();
    
        } else {
    
            $a = fopen($filename, 'r');
            $string = fread($a, 20);
            fclose($a);
    
            $data = bin2hex(substr($string, 14, 4));
            $x = substr($data, 0, 4);
            $y = substr($data, 4, 4);
    
            $resolutions = array('x' => hexdec($x), 'y' => hexdec($y));
    
        }
    
        return $resolutions;
    }
    

提交回复
热议问题