reportlab库的ImageReader方法无效

2024-04-19 05:44:36 发布

您现在位置:Python中文网/ 问答频道 /正文

PIL库的reportlab ImageReader(“url”)不工作。 我的环境:Python3.7.6、Pizzle 7.0.0、reportlab 3.5.32(我还尝试了不同版本的PIL和reportlab…相同的错误)

img = ImageReader('https://www.google.it/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png')

我的错误

Cannot open resource "https://www.google.it/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png"
fileName='https://www.google.it/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png' identity=[ImageReader@0x119474090 filename='https://www.google.it/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png']

Tags: httpsurlpil环境pngwww错误google
1条回答
网友
1楼 · 发布于 2024-04-19 05:44:36

已解决…在reportlab上的表中使用URL图像的解决方案:

from PIL import Image as pillowImage
from django.core.files.storage import default_storage
from io import BytesIO
from reportlab.platypus import Image

cloud_image = default_storage.open('url') # using s3Storage 
img = pillowImage.open(cloud_image)
img_byte_arr = BytesIO()
img.save(img_byte_arr, format=img.format)
result = Image(img_byte_arr, w * cm, h * cm)

....
data1 = [[result]]

t1 = Table(data1, colWidths=(9 * cm))
t1.setStyle(TableStyle([('VALIGN', (0, 0), (-1, -1), 'LEFT'),]))
t1.hAlign = 'LEFT'

story.append(t1)
...

相关问题 更多 >