title: Save CGImageRef as PNG-8
body: <p>I'm wondering how to save a CGImageRef as a palette-based PNG-8 file.</p>
  
  <p>I have the following code for PNG-24:</p>
  
  <pre><code>CFURLRef url = (CFURLRef)[[NSURL alloc] initFileURLWithPath:path];
  
  CGImageDestinationRef destination = CGImageDestinationCreateWithURL(url, kUTTypePNG, 1, NULL);
  CGImageDestinationAddImage(destination, image, properties);
  CGImageDestinationFinalize(destination);
  </code></pre>
  
  <p>Looking to convert this to PNG-8 now. If I do need to use libpng, how would you rewrite this?</p>