title: How to remove exif from a JPG without losing image quality?
body: <p>I have a PHP photo sharing application in which user-uploaded images are resized into various thumb formats using ImageMagick.</p>
  
  <p>As a seemingly "smart" way to save on file size, I am stripping exif info from these thumbs as follow:</p>
  
  <pre><code>$imagick = new Imagick($image);
  $imagick-&gt;stripImage();
  $imagick-&gt;writeImage($image);
  </code></pre>
  
  <p>This works. It does remove the EXIF info, where a thumbs of 30KB saves 12KB and becomes 18KB. A significant saving when showing many of such thumbs on a single page.</p>
  
  <p>The problem however is that it works a little too well. The resulting images seem to lose a lot of color information and look "flat" compared to their non-stripped versions.</p>
  
  <p>Based on my research so far, my theory is that one or both of the following is true:</p>
  
  <ul>
  <li>Imagick throws away essential color profile information as part of the stripping process</li>
  <li>Imagick recompresses the image upon saving it, losing quality</li>
  </ul>
  
  <p>Regardless of the cause of the problem, I'm looking for a way to remove EXIF information in such a way that it does not affect the image quality or color itself. </p>
  
  <p>Is this even possible?</p>
  
  <p><strong>Update:</strong></p>
  
  <p>Based on Gerald Schneider's answer, I tried enforcing the quality setting to 100% prior to "stripping" the image:</p>
  
  <pre><code>$imagick = new Imagick($image);
  $imagick-&gt;setCompression(imagick::COMPRESSION_JPEG);
  $imagick-&gt;setCompressionQuality(100);
  $imagick-&gt;stripImage();
  $imagick-&gt;writeImage($image);
  </code></pre>
  
  <p>Unfortunately, the problem remains. Below is example output where despite setting the quality to 100%, images are still flattened. </p>
  
  <p><img src="https://i.stack.imgur.com/IwALK.jpg" alt="enter image description here"></p>