[Python] How do i set the max size for an image in Reportlab, without rescaling?

Discussão em 'Python' iniciado por Stack, Agosto 14, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to generate an pdf using Reportlab. It is acceptably easy. I have a function like the one below that returns the image and I just add it to the document.

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


    It works but not as I want it to. The problem I have is that it rescales my image. E.g. If i have an image 3000px(width) x 1000px (height) which has a scale 1 to 3, i get in the pdf a rescaled image: 1 to 2.

    What i basically want is to just specify the maximum width and height and let reportlab resize it (not rescale it), if the image is too big.

    Can this be done in Reportlab or should I do that myself?

    Thanks!

    Continue reading...

Compartilhe esta Página