title: PPM/PNG to GIF conversion results in very low quality
body: <p>The raytracer we're programming generates simple PPM image files. We wrote a little something that generates scene definitions for us, so that we can create an animation with these files.</p>
  
  <p>The initial workflow was opening all files in Photoshop via <em>File > Scripting > Load Files into Stack</em> and exporting the result as a gif. This works well, although the workflow is bumpy. The quality is good, the file size huge.</p>
  
  <p>Now when using ImageMagick to convert from PPM to GIF, the quality of the resulting image is horrible. That is, the quality of <strong>single</strong> GIF files produced by ImageMagick is already bad. Combining them to a GIF of course does not change that.</p>
  
  <p><strong>Original File (saved as PNG with Photoshop):</strong></p>
  
  <p><a href="https://i.stack.imgur.com/k1jD7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/k1jD7.png" alt="Test file saved as PNG with Photoshop"></a></p>
  
  <p><strong>GIF (converted from PPM with ImageMagick):</strong></p>
  
  <p><a href="https://i.stack.imgur.com/N87bj.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/N87bj.gif" alt="Test file converted from PPM with ImageMagick"></a></p>
  
  <p><em>(Especially notice the spots around the point where the light emits)</em></p>
  
  <p>I just used <code>mogrify -path ../gif -format gif 006.ppm</code> for that result. I don't really know where to start to tweak this (although I played around with a couple of options from the <a href="http://www.imagemagick.org/script/mogrify.php#options" rel="nofollow noreferrer">reference</a>).</p>
  
  <h2>Further Notes:</h2>
  
  <ul>
  <li>For reference, here are some example files (<a href="https://github.com/kleinfreund/raytracer/blob/master/assets/006-original.ppm" rel="nofollow noreferrer">original ppm file</a>, ImageMagick gif, …) to play with: <a href="https://github.com/kleinfreund/raytracer/tree/master/assets" rel="nofollow noreferrer">https://github.com/kleinfreund/raytracer/tree/master/assets</a></li>
  <li>Quality is very good when exporting a single image via Photoshop (selective, diffuse dither 100%, no transparency, 256 colors, no meta data)</li>
  <li>Quality is also very good when batch-converting the PPM files to PNG with ImageMagick</li>
  <li>I'm open to other workflows, so I'm fine if you can provide an alternative solution as well</li>
  </ul>
  
  <p><a href="https://i.stack.imgur.com/KoWLm.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KoWLm.gif" alt="Comparison 1"></a></p>
  
  <p><em>(a little animation of the difference between the two files so the issues are easier to see. by Mark Setchell)</em></p>
  
  <p><a href="https://i.stack.imgur.com/Imu8t.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Imu8t.gif" alt="Comparison 2"></a></p>