title: Insert image into Reportlab either from PIL image or StringIO
body: <p>I'm trying to insert a barcode image into Reportlab.  I know there are a lot of questions asked on this, but <strong>all of them assume</strong> that you already have the image file in the directory or on the filesystem.</p>
  
  <p>Due to the fact that Reportlab has issues with EAN13 barcodes, I decided to use another package called pyBarcode to generate the image for me.</p>
  
  <p>Initially I saved the image in a StringIO instance and passed it directly to <code>reportlab.platypus.flowables.Image</code> but that didn't seem to work.  Then I read the documentation:</p>
  
  <blockquote>
    <p>Formats supported by PIL/Java 1.4 (the Python/Java Imaging Library) are supported.</p>
  </blockquote>
  
  <p>Does this mean that if I pass a PIL image, this should work?  I got an exception when I tried the following:</p>
  
  <pre><code>&gt;&gt;&gt; import PIL
  &gt;&gt;&gt; from reportlab.platypus.flowables import Image
  &gt;&gt;&gt; fp = StringIO(the_barcode.getvalue())
  &gt;&gt;&gt; barcode_image = PIL.Image.open(fp)
  &gt;&gt;&gt; doc = SimpleDocTemplate('barcode.pdf')
  &gt;&gt;&gt; story = [Image(barcode_image)]
  &gt;&gt;&gt; Traceback (most recent call last):
    File "create.py", line 57, in &lt;module&gt;
      main()
    File "create.py", line 24, in main
      save_pdf(fp, STYLE, ART, COLOR, SIZE)
    File "create.py", line 28, in save_pdf
      fp = StringIO(fp.getvalue())
    File "/home/mark/.virtualenvs/barcode/local/lib/python2.7/site-packages/reportlab-2.6-py2.7-linux-i686.egg/reportlab/platypus/flowables.py", line 402, in __init__
      if not fp and os.path.splitext(filename)[1] in ['.jpg', '.JPG', '.jpeg', '.JPEG']:
    File "/home/mark/.virtualenvs/barcode/lib/python2.7/posixpath.py", line 95, in splitext
      return genericpath._splitext(p, sep, altsep, extsep)
    File "/home/mark/.virtualenvs/barcode/lib/python2.7/genericpath.py", line 91, in _splitext
      sepIndex = p.rfind(sep)
    File "/home/mark/.virtualenvs/barcode/local/lib/python2.7/site-packages/PIL/Image.py", line 512, in __getattr__
      raise AttributeError(name)
  AttributeError: rfind
  </code></pre>
  
  <p>Somehow PIL Image doesn't seem to work either.  What should I pass as the first argument to Reportlab's Image function if I don't have the filename of the image (because my images are created in memory)?</p>