title: How do I convert a CSV file to an RGB image using python
body: <p>I'm trying to convert a csv file to an RGB file as follows:</p>
  
  <pre><code>from PIL import Image, ImageDraw
  from numpy import genfromtxt
  
  g = open('myFile.csv','r')
  temp = genfromtxt(g, delimiter = ',')
  im = Image.fromarray(temp).convert('RGB')
  pix = im.load()
  rows, cols = im.size
  for x in range(cols):
      for y in range(rows):
          print str(x) + " " + str(y)
          pix[x,y] = (int(temp[x,y] // 256 // 256 % 256),int(temp[x,y] // 256 % 256),int(temp[x,y] % 256))
  im.save(g.name[0:-4] + '.jpeg')
  </code></pre>
  
  <p>The issue is that the second last line is giving me a "IndexError: image index out of range". when I print out x and y I see that it happens whenever either of them reaches 5 which is the width of my file, but not the height, no matter how I play with it, whether x or y reaches 5, it throws an error and that's what I'm not figuring out. Any better implementations are also welcome.</p>