[reportlab-users] questions about maximum image sizes and possible bug in 1.18
Ryan Grow
reportlab-users@reportlab.com
Sun, 3 Aug 2003 10:53:54 -0700 (PDT)
Greetings,
I apologize in advance if this message is too long for
this mailing list.
I am using reportlab 1.17 on Windows XP home edition -
except in one case detailed below where I use 1.18 and
the behavior is different. ( it hangs indefinitely in
the build call )
I have found that if I have a frame around a page and
I try to append an image that is wider than the frame,
report labs 1.17 handles this fine. Obviously it clips
the image, but it does a reasonable job of displaying
what it can within the width of the page.
Interestingly, though, the left and right sides of the
image do get displayed beyond the width of the frame
all the way to the edges of the page.
However, if I try to append an image that is taller
than a certain threshold relative to the height of the
frame, in reportlab 1.17 I get the following exception
which I would expect to get when the image is too wide
as well:
File "testimage.py", line 60, in ?
t.build()
File "testimage.py", line 35, in build
BaseDocTemplate.build(self, pdfItems)
File
"c:\Python22\reportlab\platypus\doctemplate.py", line
579, in build
self.handle_flowable(flowables)
File
"c:\Python22\reportlab\platypus\doctemplate.py", line
525, in handle_flowable
raise "LayoutError", message
LayoutError: Flowable <Image at 8070328
filename=testimage.jpg> too large on page 2
Now - if I run the exact same code using reportlab
1.18, the program hangs indefinitely, which seems
like it may be a bug in reportlab 1.18 - or at least
an undocumented behavior.
Now for my next question - what is the maximum
allowable size (height and width) of an image that I
can expect to put within a frame relative to the size
of the frame and be supported in future versions of
reportlab? The behavior I'm seeing with 1.17 indicates
that I can create an image as wide as I want, and the
height must be some constant number of units shorter
than the height of the frame. If I know for certain
what this restriction is, then I can write my
application so that I don't encounter the 'image too
large' or the 'indefinite hanging' problem.
Is reportlabs supposed to scale an image size down if
I provide a w and h to the Image class that is
actually smaller than the width and height of the jpg
image? This seems to work except in the case where the
image is taller than the page. In that case, it seems
as though reportlabs ignores my height specification
and gives me the 'image too large' error.
And finally, if I use an image that has resolution
greater than 72 dpi, are the w and h parameters
provided to the Image constructor still relative to 72
dpi units or do I set these values equal to the number
of pixels in the x and y dimensions?
I have included some source code below which causes
reportlab1.18 to hang in the BaseDocTemplate.build
call. This assumes there is an image in the same
directory called testimage.jpg.
import sys
from reportlab.lib.pagesizes import letter
from reportlab.lib.units import inch
from reportlab.platypus import *
xMargin = 0.25 * inch
yMargin = 0.25 * inch
#
# Attempting to recreate problems I'm having with
larger image sizes within page frames
# in report labs and to experiment with images at
different resolutions.
#
class TestPageTemplate(BaseDocTemplate):
def __init__(self, filename, pageSize=letter):
self.pageWidth = pageSize[0]
self.pageHeight = pageSize[1]
BaseDocTemplate.__init__(self, filename)
def afterInit(self):
self.addPageTemplates(FramedTemplate(self.pagesize))
def build(self):
pdfItems = []
pdfItems.append(NextPageTemplate('frame'))
pdfItems.append(Image(filename="testimage.jpg",
width = 600,
height = 900))
pdfItems.append(PageBreak())
BaseDocTemplate.build(self, pdfItems)
class FramedTemplate(PageTemplate):
def __init__(self, pageSize=letter):
self.pageWidth = pageSize[0]
self.pageHeight = pageSize[1]
imageFrame = Frame(xMargin,
yMargin,
self.pageWidth - (xMargin *
2),
self.pageHeight - (yMargin
* 2),
id = 'testimage',
showBoundary = 1)
PageTemplate.__init__(self, 'frame',
[imageFrame])
if __name__=="__main__":
print "starting"
t = TestPageTemplate("testpage.pdf")
t.build()
print "created testpage.pdf"
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com