08.21.2019

Get Image DPI (Image Resolution) without using Imagick or GD library in PHP

PHP function simply get image DPI in PHP without Imagick or GD library

Use this PHP function to get resolution (image dpi).
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));
}

Just call
get_dpi("image.jpg");
That's all thing we need to do.

Leave a comment