Re: Image within a table - Preserve Aspect Ratio
Robin Becker <[email protected]>
| Newsgroups | gmane.comp.python.reportlab.user |
|---|---|
| Message-ID | <CAOBYczp514fvKyEsSFPAxLnj4YrbGBzx8Wu+HhRhNTeJanBRNQ@mail.gmail.com> |
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) < [email protected]> 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 > [email protected] > https://pairlist2.pair.net/mailman/listinfo/reportlab-users > -- Robin Becker