Метод ImageReader библиотеки reportlab не работает - PullRequest
0 голосов
/ 08 января 2020

reportlab ImageReader ('url') библиотеки PIL не работает. мой env: Python 3.7.6, Pillow 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']

1 Ответ

0 голосов
/ 09 января 2020

Решено ... Решение с использованием изображений 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)
...
...