If knowledge is power, then sharing knowledge is ultimate powertrip
Latest Updates
You are here: Home >> PHP >> get dpi of image in php

get dpi of image in php

To get DPI of image in PHP, you can use the following code

<?php
function get_dpi($filename){

// open the file and read first 20 bytes.
$a = fopen($filename,’r’);
$string = fread($a,20);
fclose($a);

// get the value of byte 14th up to 18th
$data = bin2hex(substr($string,14,4));
$x = substr($data,0,4);
$y = substr($data,4,4);
return array(hexdec($x),hexdec($y));

}

// sample, output the result:
print_r(get_dpi(‘demo_files/abc.png’));
?>

About Jawed Shamshedi

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

Scroll To Top