title: In Python 3, best way to open an image stored in a list as a file object?
body: <p>Using python 3.4 in linux and windows, I'm trying to create qr code images from a list of string objects. I don't want to just store the image as a file because the list of strings may change frequently. I want to then tile all the objects and display the resulting image on screen for the user to scan with a barcode scanner. For the user to know which code to scan I need to add some text to the qr code image. </p>
  
  <p>I can create the list of image objects correctly and they are in a list and calling .show on these objects displays them properly but I don't know how to treat these objects as a file object to open them. The object that is given to the open function, (<code>img_list[0]</code> in my case), in my <code>add_text_to_img</code> needs to support <code>read</code>, <code>seek</code> and <code>tell</code> methods. When I try this as is I get an attribute error. I've tried BytesIO and StringIO but I get an error message that Image.open does not support buffer interface.  Maybe I am not doing that part correctly.</p>
  
  <p>I'm sure there are several ways to do this, but what is the best way to open in memory objects as a file object?</p>
  
  <pre><code>from io import BytesIO
  import qrcode
  from PIL import ImageFont, ImageDraw, Image
  
  def make_qr_image_list(code_list):
      """
  
      :param code_list:   a list of string objects to encode into QR code image
      :return:            a list of image or some type of other data objects
      """
      img_list = []
      for item in code_list:
          qr = qrcode.QRCode(
                              version=None,
                              error_correction=qrcode.ERROR_CORRECT_L,
                              box_size=4,
                              border=10
                              )
          qr.add_data(item)
          qr_image = qr.make_image(fit=True)
          img_list.append(qr_image)
  
      return img_list
  
  def add_text_to_img(text_list, img_list):
      """
      While I was working on this, I am only saving the first image. Once
      it's working, I'll save the rest of the images to a list.
      :param text_list:   a list of strings to add to the corresponding image.
      :param img_list:    the list containing the images already created from
                          the text_list
      :return:
      """
      base = Image.open(img_list[0])
      # img = Image.frombytes(mode='P', size=(164,164), data=img_list[0])
      text_img = Image.new('RGBA', base.size, (255,255,255,0))
  
      font    = ImageFont.truetype('sans-serif.ttf', 10)
      draw    = ImageDraw.Draw(text_img)
      draw.text((0,-20),text_list[0], (0,0,255,128), font=font)
      #  include some method to save the images after the text
      #  has been added here. Shouldn't actually save to a file.
      #  Should be saved to memory/img_list
      output = Image.alpha_composite(base,text_img)
      output.show()
  
  if __name__ == '__main__':
      test_list   = ['AlGaN','n-AlGaN','p-AlGaN','MQW','LED AlN-AlGaN']
      image_list  = make_qr_image_list(test_list)
      add_text_to_img(test_list, image_list)
      im          = image_list[0]
      im.save('/my_save_path/test_image.png')
      im.show()
  </code></pre>
  
  <p>Edit: I've been using python for about a year and I feel like this is a pretty common thing to do but I'm not even sure that I'm looking up/searching for the right terms. What topics would you search for to answer this? If anyone can post a link or two to what I need to read up on regarding this, that would be very appreciated.</p>