title: Save grayscale image as 4 bit png with python
body: <p>I am looking for a fast way to save a grayscale image as a 4-bit png with python. The images that I have to save are quite big, so saving them takes quite some time.</p>
  
  <p>Suppose my image is stored in a numpy-array (dtype=8-bit). With PyPng I can do:</p>
  
  <pre><code>import png
  data = map(lambda x: map(int, x/17), data)
  png.from_array(data, 'L;4').save(filename)
  </code></pre>
  
  <p>This will save a proper 4-bit png. With Pillow, I can do:</p>
  
  <pre><code>import PIL.Image as Image
  im = Image.fromarray(data)
  im.save(filename)
  </code></pre>
  
  <p>The second approach (Pillow) is about 10 times as fast as the first one (even without the conversation), however the images are 8-bit pngs. I tried adding the lines</p>
  
  <pre><code>im = im.point(lambda i: i/17) # convert values
  im.mode = 'L;4'
  </code></pre>
  
  <p>but then I get <code>*** SystemError: unknown raw mode</code>, even though the Mode 'L;4' is specified in <a href="https://github.com/python-pillow/Pillow/blob/master/PIL/PngImagePlugin.py" rel="nofollow">https://github.com/python-pillow/Pillow/blob/master/PIL/PngImagePlugin.py</a></p>
  
  <p>Does anyone know how to save 4-bit pngs with Pillow or is there another fast way to do it?</p>