[reportlab-users] Image within a table - Preserve Aspect Ratio
Robin Becker
robin at reportlab.com
Sat Feb 23 03:29:09 EST 2019
Currently Image doesn't allow for an automatic preserve aspect ratio. It
has to be done like this
1) obtain the image width and height
2) call
_x,_y, w, h, _scale
=reportlab.lib.boxstuff.aspectRatioFix(1,'sw',x,y,width,height,imWidth,imHeight)
I think the _x/y/scale van be ignored for your purpose. The adjusted
image width and height should
be used to construct the Image object that's passed to the table.
I agree this is a bit clunky, but getting the width and height sperately
would allow you to specify the table size as well.
On Fri, 22 Feb 2019 at 20:56, Pizzolato, Larissa (EC) <
larissa.pizzolato at canada.ca> wrote:
> Hi all,
>
>
>
> I would like to add an image within a table (example below - maxIMAGE),
> but would like the aspect ratio to be preserved.
>
> from reportlab import platypus as platy
>
> maxIMAGE = platy.Image(maxIMAGE_path,2.2*inch, 2.2*inch)
>
> maxIMAGE_table = Table([[maxIMAGE]],2.3*inch, 2.3*inch,
> style=[('GRID',(0,0),(0,0),.5, 'black'), ('BACKGROUND',(0,0),(0,0),
> "white"),('ALIGN',(0,0),(0,0), 'CENTER'),('VALIGN',(0,0),(0,0), 'MIDDLE')])
>
>
>
>
>
> However, when I try doing preserveAspectRatio=True, I receive the
> following error:
>
> TypeError: __init__() got an unexpected keyword argument
> ‘preserveAspectRatio’
>
>
>
> I’ve also tried the solution listed here:
> https://stackoverflow.com/questions/5327670/image-aspect-ratio-using-reportlab-in-python
> with no success.
>
>
>
> Is there another way to render the image into the table that has this
> capability?
>
>
>
> Any ideas?
>
>
>
> Cheers!
> _______________________________________________
> reportlab-users mailing list
> reportlab-users at lists2.reportlab.com
> https://pairlist2.pair.net/mailman/listinfo/reportlab-users
>
--
Robin Becker
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist2.pair.net/pipermail/reportlab-users/attachments/20190223/4644c316/attachment.html>
More information about the reportlab-users
mailing list