Search code examples
phpimagedensity-independent-pixel

How to get Image DPI in PHP


I am searching for the code which could help me to get the Image DPI in PHP.

Could any one look into this ?

Thanks in advance.


Solution

  • You can go for some image libraries for that. Eg: Imagick, GD Library...

    (OR)

    You can use the following function,

    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,0,4);
    
        return array(hexdec($x),hexdec($y));
    } 
    

    Already solved this question here... :)