Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Check Photo DPI with PHP [duplicate]

Possible Duplicate:
Get/set DPI with PHP GD/Imagick?

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

like image 417
Flash Avatar asked May 05 '11 04:05

Flash


People also ask

How can I get image DPI in PHP?

PHP | imageresolution() Function. The imageresolution() function is an inbuilt function in PHP which is used to set and return the resolution of an image in DPI (dots per inch). If none of the optional parameters is given, the current resolution is returned as an indexed array.

How do I know what DPI my photo is?

To find out an image's DPI in Windows, right-click on the file name and select Properties > Details. You'll see the DPI in the Image section, labeled Horizontal Resolution and Vertical Resolution.


1 Answers

If you want it without Imagick or GD Library. I was struggling with this, and since I found it, here you go.

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

and then print the array or do with it what you want.

like image 69
Naeem Avatar answered Oct 10 '22 07:10

Naeem