Differences between revisions 5 and 6
Revision 5 as of 2015-05-23 02:59:17
Size: 312
Editor: FloridaLei
Comment:
Revision 6 as of 2015-05-23 05:37:03
Size: 2254
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
Not much to say about me at all.<<BR>><<BR>>
Great to be a member of this site.<<BR>><<BR>>
I really wish I'm useful at all<<BR>><<BR>>
<<BR>><<BR>>
Feel free to visit my blog - summoners war hack ([[http://www.wattpad.com/113192113-summoners-war-hack-2015-summoners-war-online-hack|Recommended Web page]])
= The Problem =

Using [[http://www.reportlab.org|repotlab]] and following the instructions from [[py2exeAndPIL]].

Still, when
{{{
#!python
from reportlab.lib.utils import ImageReader
im=ImageReader(someCstringIOStream())
}}}

raises "cannot identify image file"

= Explanation =

Reportlab does some different things when importing Image from PIL

excerpt from reportlab.lib.utils
{{{
#!python
class ImageReader:
    "Wraps up either PIL or Java to get data from bitmaps"
    def __init__(self, fileName):
        if not haveImages:
            warnOnce('Imaging Library not available, unable to import bitmaps')
            return
        #start wih lots of null private fields, to be populated by
        #the relevant engine.
        self.fileName = fileName
        self._image = None
        self._width = None
        self._height = None
        self._transparent = None
        self._data = None

        #detect which library we are using and open the image
        if sys.platform[0:4] == 'java':
            from javax.imageio import ImageIO
            if type(fileName) is type(''):
                fp = open(fileName,'rb')
            else:
                fp = fileName
            self._image = ImageIO.read(fp)
        else:
            import PIL.Image
            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...


{{{
#!python

class MyImageReader(ImageReader):
    """ Kopie des Report-Lab Image Readers, kommt besser mit
        py2exeter PIL zurande"""
    def __init__(self, fileName):
        #start wih lots of null private fields, to be populated by
        #the relevant engine.
        self.fileName = fileName
        self._image = None
        self._width = None
        self._height = None
        self._transparent = None
        self._data = None

        #änderung: kein Detect oder so, DIES IST WINDOWS
        # PIL IST VORHANDEN
            
        self._image = Image.open(fileName)
}}}

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

HAM2004-08-09

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 2015-05-23 05:37:03 by JimmyRetzlaff)