Differences between revisions 3 and 4
Revision 3 as of 2004-10-11 15:40:38
Size: 2256
Editor: www
Comment:
Revision 4 as of 2008-07-08 11:27:43
Size: 2254
Editor: localhost
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
Using [http://www.reportlab.org repotlab] and following the instructions from ["PIL and py2exe"]. Using [[http://www.reportlab.org|repotlab]] and following the instructions from [[py2exeAndPIL]].
Line 77: Line 77:
Image has to be imported and "tuned" as described in ["PIL and py2exe"] Image has to be imported and "tuned" as described in [[py2exeAndPIL]]

The Problem

Using repotlab and following the instructions from py2exeAndPIL.

Still, when

   1 from reportlab.lib.utils import ImageReader
   2 im=ImageReader(someCstringIOStream())

raises "cannot identify image file"

Explanation

Reportlab does some different things when importing Image from PIL

excerpt from reportlab.lib.utils

   1 class ImageReader:
   2     "Wraps up either PIL or Java to get data from bitmaps"
   3     def __init__(self, fileName):
   4         if not haveImages:
   5             warnOnce('Imaging Library not available, unable to import bitmaps')
   6             return
   7         #start wih lots of null private fields, to be populated by
   8         #the relevant engine.
   9         self.fileName = fileName
  10         self._image = None
  11         self._width = None
  12         self._height = None
  13         self._transparent = None
  14         self._data = None
  15 
  16         #detect which library we are using and open the image
  17         if sys.platform[0:4] == 'java':
  18             from javax.imageio import ImageIO
  19             if type(fileName) is type(''):
  20                 fp = open(fileName,'rb')
  21             else:
  22                 fp = fileName
  23             self._image = ImageIO.read(fp)
  24         else:
  25             import PIL.Image
  26             self._image = PIL.Image.open(fileName)

Solution

Make it dumb. We know: This is not Java, this is Windows. We have PIL, because we use py2exe and ARE responsible to put it into the package. So...

   1 class MyImageReader(ImageReader):
   2     """ Kopie des Report-Lab Image Readers, kommt besser mit
   3         py2exeter PIL zurande"""
   4     def __init__(self, fileName):
   5         #start wih lots of null private fields, to be populated by
   6         #the relevant engine.
   7         self.fileName = fileName
   8         self._image = None
   9         self._width = None
  10         self._height = None
  11         self._transparent = None
  12         self._data = None
  13 
  14         #änderung: kein Detect oder so, DIES IST WINDOWS
  15         # PIL IST VORHANDEN
  16             
  17         self._image = Image.open(fileName)

Image has to be imported and "tuned" as described in py2exeAndPIL

HAM2004-08-09

PILAndReportlab (last edited 2008-07-08 11:27:43 by localhost)