How to check photo DPI using PHP

Possible duplicate:
Get / set DPI using PHP GD / Imagick?

Is there any way to check photo using php. I have photos with a resolution of 300 dpi and 72 dpi. but wants to automatically calculate dpi.

+5
source share
2 answers

It’s too late for me to check, but I think what you are looking for Imagick::getImageResolution()and Imagick::setImageResolution()if you need to change the DPI.

I don’t think it’s possible with GD, I believe that it “converts” all images to 72 DPI.

+2
source

If you want it without Imagick or GD Library. I struggled with this, and since I found it, you are here.

function get_dpi($filename){
    $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);

    return array(hexdec($x),hexdec($y));
}

, .

+13

All Articles