title: pixel by pixel reconstruct image in python
body: <p>I have a script that lists all the pixel data in hex from an image. Does PIL or similar library have an easy way to reconstruct the image from the output text? This is what I use to get the data</p>
  
  <pre><code>#!/usr/bin/python
  from PIL import Image
  
  def rgb2hex(r, g, b):
      return '#{:02x}{:02x}{:02x}'.format(r, g, b)
  
  img = Image.open('apple_raw.png')
  
  if img.mode in ('RGBA', 'LA') or (img.mode == 'P' and 'transparency' in img.info):   
      pixels = img.convert('RGBA').load()
      width, height = img.size
  
      for x in range(width):
          for y in range(height):
              r, g, b, a = pixels[x, y]
              print '%s,%s,%s' % (x, y, rgb2hex(r, g, b))
  </code></pre>
  
  <p>output (snip)</p>
  
  <pre><code>0,0,#ffffff
  0,1,#ffffff
  0,2,#ffffff
  0,3,#ffffff
  0,4,#ffffff
  ...
  ...
  304,308,#ffffff
  304,309,#ffffff
  304,310,#ffffff
  304,311,#ffffff
  304,312,#ffffff
  304,313,#ffffff
  </code></pre>
  
  <p><a href="https://imgur.com/a/5YT9H" rel="nofollow noreferrer">http://imgur.com/a/5YT9H</a> image I'm using for testing</p>