프레임 안에 이미지를 삽입하고 싶습니다. 나는이 두 가지 방법을 발견 :Python에서 Reportlab을 사용하는 이미지 종횡비
- 의 drawImage (자기, 이미지, X, Y, 폭 = 없음을 높이 = 없음, 마스크 = 없음, preserveAspectRatio = 거짓, 앵커 = 'C')
- 이미지 (파일 이름, 너비 = 없음, 높이 = 없음)
질문 : 어떻게 가로 세로 비율을 유지하면서 이미지를 추가 할 수 있습니까?
from reportlab.lib.units import cm
from reportlab.pdfgen.canvas import Canvas
from reportlab.platypus import Frame, Image
c = Canvas('mydoc.pdf')
frame = Frame(1*cm, 1*cm, 19*cm, 10*cm, showBoundary=1)
"""
If I have a rectangular image, I will get a square image (aspect ration
will change to 8x8 cm). The advantage here is that I use coordinates relative
to the frame.
"""
story = []
story.append(Image('myimage.png', width=8*cm, height=8*cm))
frame.addFromList(story, c)
"""
Aspect ration is preserved, but I can't use the frame's coordinates anymore.
"""
c.drawImage('myimage.png', 1*cm, 1*cm, width=8*cm, preserveAspectRatio=True)
c.save()
이 해결 방법을 이용해 주셔서 감사합니다. 누군가가 이것을 API에 추가하기를 바랍니다. – citn
이것은이 질문에 대한 최선의 대답입니다. 우리가 이와 비슷한 질문을 병합해야합니다. – jimh