[reportlab-users] Error reporting: please say what image is failing
Robin Becker
robin at reportlab.com
Thu Mar 18 07:04:29 EDT 2010
On 18/03/2010 10:38, Andy Robinson wrote:
> On 18 March 2010 09:55, Robin Becker<robin at reportlab.com> wrote:
>> we can if it's given as a string, and perhaps, as a file like object. Maybe
>> Roberto can give some indication of where the image comes from and perhaps a
>> sample.
>
>
> One more idea: if people are passing in file-like objects, perhaps we
> could allow an optional argument (audit_trail="foo.jpg"?) to the
> image constructor or function. If an error occurs and we were not
> given a filename or URL, we could add that argument to the args for
> the exception.
the place for this information is on the filelike object. I believe that is
intended for files that are opened by path eg
>>>> f=file('/tmp/aaa','r')
>>>> f.name
> '/tmp/aaa'
>>>>
so logically we should try for obj.name as that's the common case. For the
standard StringIO case nothing prevents use of a name on the object.
>>>> import StringIO
>>>> s=StringIO.StringIO(buf='aaaa')
>>>> s.name='aaaa'
>>>>
but that won't work for cStringIO and may not for sockets. We're already trying
to handle the case of PIL images being passed in.
>
> Examples: some systems have big databases of images or pull them from
> a database connection, so will be passing us file-like objects. The
> programmer can then separately add an identifier.
>
the danger with names at the point of call is that they often end up as
completely generic names from a template location. I think we should allow an
ImageReader identifier, but also report any name decided from the file pointer
since that will be more specific.
> Roberto, how should rst2pdf behave if an image is missing? Should it
> fail on first error, or does it have any modes to continue-but-warn,
> or put dummy image placeholders in the PDF? You probably have
> issues we have had in the past with RML...
>
Looking in the ImageReader code there is a specific exception being made for PIL
1.1.7 because that did cause a problem with split ie
if mode=='RGBA':
if Image.VERSION.startswith('1.1.7'): im.load()
self._dataA = ImageReader(im.split()[3])
im = im.convert('RGB')
self.mode = 'RGB'
can we find some details on the PIL version etc etc.
.......
--
Robin Becker
More information about the reportlab-users
mailing list