I want to insert an image inside a frame. I found two ways to do this:
- Picture (self, image, x, y, width = none, height = none, mask = none, preserveApectRatio = False, anchor = ' C ')
- Image (filename, width = none, height = none)
My question is: When I preserve my frame ratio How can I add an image to a frame? Importlab.pdfgen.canvas import from importlab.lib.units reportlab.platypus import frame from Image, Image C = import from canvas ('mydoc.pdf') frame = frame (1 * cm) / p>
< Code>, 1 * cm, 19 * centimeter, 10 * cm, showbayer = 1) "" "If I have a rectangular image, I will get a square image (shape ration will change to 8x8 cm). Coordinates. "" Story = [] story.append (image ('myimage.png', width = 8 * centimeters, height = 8 * cm)) frame. AddFromList (story, c) "" aspect ration is protected But I can no longer use frames of coordinates. "C.drawImage ('myimage.png', 1 * cm, 1 × cm, width = 8 * cm, preserveAspectRatio = true) c.save ()
You can use the size of the original image to calculate your pattern ratios, then use it to measure your target width, height You can wrap it in a function to make it reusable:
import utils def get_image (path, width = 1 * cm) from reportlab.lib: img = utils.ImageReader ( Path) iw, Ih = img.getSize () aspect = ih / float (iw) returns Story: (story, width = width, height = (width * aspect) , Width = 8 * cm)) frame.addFromList (story, c)
A 248 x 70 pixel stack. 01:
Comments
Post a Comment