title: How to get quality of image in PHP
body: <p>I've been doing some speed optimization on my site using Page Speed and it gives recommendations like so:</p>
  
  <pre><code>Optimizing the following images could reduce their size by 35.3KiB (21% reduction).
  
  Losslessly compressing http://example.com/.../some_image.jpg could save 25.3KiB (55% reduction).
  </code></pre>
  
  <p>How are the calculations done to get the file size reduction numbers? How can I determine if an image is optimized in PHP?</p>
  
  <p>As I understand it, they seem to base this on the image quality (so saving at 60% in Photoshop or so is considered optimized?).</p>
  
  <p>What I would like to do is once an image is uploaded, check if the image is fully optimized, if not, then optimize it using a PHP image library such as GD or ImageMagick. If I'm right about the number being based on quality, then I will just reduce the quality as needed.</p>
  
  <p>How can I determine if an image is fully optimized in the standards that Page Speed uses?</p>