title: Google PageSpeed & ImageMagick JPG compression
body: <p>Given a user uploaded image, I need to create various thumbnails of it for display on a website. I'm using ImageMagick and trying to make Google PageSpeed happy. Unfortunately, no matter what <code>quality</code> value I specify in the <code>convert</code> command, PageSpeed is still able to suggest compressing the image even further.</p>
  
  <p>Note that <a href="http://www.imagemagick.org/script/command-line-options.php?ImageMagick=2khj9jcl1gd12mmiu4lbo9p365#quality" rel="noreferrer">http://www.imagemagick.org/script/command-line-options.php?ImageMagick=2khj9jcl1gd12mmiu4lbo9p365#quality</a> mentions:</p>
  
  <blockquote>
    <p>For the JPEG ... image formats,
    quality is 1 [provides the] lowest
    image quality and highest compression
    ....</p>
  </blockquote>
  
  <p>I actually even tested compressing the image using 1 (it produced an unusable image, though) and PageSpeed still suggests that I can still optimize such image by "losslessly compressing" the image. I don't know how to compress an image any more using ImageMagick. <strong>Any suggestions?</strong></p>
  
  <p>Here's a quick way to test what I am talking about:</p>
  
  <pre><code>assert_options(ASSERT_BAIL, TRUE);
  
  // TODO: specify valid image here
  $input_filename = 'Dock.jpg';
  
  assert(file_exists($input_filename));
  
  $qualities = array('100', '75', '50', '25', '1');
  $geometries = array('100x100', '250x250', '400x400');
  
  foreach($qualities as $quality)
  {
      echo("&lt;h1&gt;$quality&lt;/h1&gt;");
      foreach ($geometries as $geometry)
      {
          $output_filename = "$geometry-$quality.jpg";
  
          $command = "convert -units PixelsPerInch -density 72x72 -quality $quality -resize $geometry $input_filename $output_filename";
          $output  = array();
          $return  = 0;
          exec($command, $output, $return);
  
          echo('&lt;img src="' . $output_filename . '" /&gt;');
  
          assert(file_exists($output_filename));
          assert($output === array());
          assert($return === 0);
      }
  
      echo ('&lt;br/&gt;');
  }
  </code></pre>