Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The repetitive declaration "Formats supported by PIL/Java 1.4 (the Python/Java Imaging Library) are supported" simply means that data formats supported by <code>PIL</code> are supported by <code>reportlab</code> (since it uses <code>PIL</code> to read them).</p> <p>Now, from peeking in <code>reportlab.platypus.flowables.Image</code> code it is possible to see that it accepts either a filename or a file object as input. The former is not what you want, so let us focus on the later. You said <code>StringIO</code> didn't seem to work, but it does if you take some care. You probably did something wrong with it, here are two correct ways to use <code>StringIO</code>:</p> <pre><code>import sys import PIL from cStringIO import StringIO from reportlab.platypus.flowables import Image # Method 1 data = open(sys.argv[1]).read() img1 = StringIO(data) # Method 2 img2 = StringIO() PIL.Image.open(sys.argv[2]).save(img2, 'PNG') img2.seek(0) # Method 3 (fails) img3 = StringIO(PIL.Image.open(sys.argv[2]).tostring()) story = [Image(img1), Image(img2)] #Image(img3) </code></pre> <p>The method 3 fails because <code>img3</code> now holds the raw data of the image, so it has no idea about the actual format of this data. There is no reason to attempt to use this method for such task.</p> <p>If you have raw data and you know the image mode of your data ('L', 'RGB', etc) and also its width, height, then you can use a fourth (correct) method based on <code>PIL.Image.fromstring(...).save(mystrio, 'someformat')</code>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload