title: Fetch DPI from JPEG without library returns incorrect result
body: <p>I obtained a function that can read DPI value from JPEG <a href="https://stackoverflow.com/a/12988682/188331">here</a>.</p>
  
  <pre><code>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));
  }
  </code></pre>
  
  <p>However, when I check an image created by Photoshop at 300DPI, it incorrectly returns the value of 42DPI.</p>
  
  <p><a href="https://i.stack.imgur.com/nyKPO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nyKPO.png" alt="Photoshop CC screenshot"></a></p>
  
  <p>What did I miss? </p>
  
  <hr>
  
  <p>The problematic image generated by Photoshop: <a href="https://drive.google.com/open?id=117LHlgpefXZsuiVSl_nMG6MUQfKcT1MI" rel="nofollow noreferrer">https://drive.google.com/open?id=117LHlgpefXZsuiVSl_nMG6MUQfKcT1MI</a></p>
  
  <p><strong>UPDATE</strong>: I tried an <a href="https://convert-dpi.com/" rel="nofollow noreferrer">online DPI converter</a> to regenerate the JPEG at 300DPI, the PHP function reports the correct value, 300DPI.</p>
  
  <p>The regenerated image: <a href="https://drive.google.com/open?id=1-C4GZ8_K4wit3sISz21ngd4OVlLXuL72" rel="nofollow noreferrer">https://drive.google.com/open?id=1-C4GZ8_K4wit3sISz21ngd4OVlLXuL72</a></p>
  
  <p>I compared the metadata of 2 JPEGs, the generated JPEG has JIFF information, but the initial JPEG does not. Is that the cause of the problem?</p>
  
  <p><em>Given that I don't have Imagick library, I can't use its <code>getImageResolution()</code> function to read the value.</em></p>