如何在不重新缩放的情况下在Reportlab中设置图像的最大大小?

我正在尝试使用Reportlab生成pdf.这很容易接受.我有一个像下面那样的函数返回图像,我只是将它添加到文档中.

def create_logo(bsolute_path):
   image = Image(absolute_path)
   image.drawHeight = 1 * inch
   image.drawWidth = 2 * inch
   return [image]

它有效但不是我想要的.我遇到的问题是它重新调整了我的图像.
例如.如果我有一个图像3000px(宽度)x 1000px(高度),其比例为1到3,我在pdf中得到一个重新缩放的图像:1到2.

我基本上想要的是只指定最大宽度和高度,如果图像太大,让reportlab调整大小(不重新缩放).

这可以在Reportlab中完成,还是我自己应该这样做?

谢谢!

最佳答案 我也发现了这个:

Image aspect ratio using Reportlab in Python

但最后我用这个方法:

def create_logo(absolute_path):
    image = Image(absolute_path)
    image._restrictSize(2 * inch, 1 * inch)
点赞