【问题标题】:ImageReader method of reportlab library does not workreportlab 库的 ImageReader 方法不起作用
【发布时间】:2020-01-08 13:35:09
【问题描述】:
PIL 库的

reportlab ImageReader('url') 不起作用。 我的环境: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']

【问题讨论】:

    标签: python python-imaging-library reportlab


    【解决方案1】:

    已解决...在 reportlab 上的表格中使用 urls 图像的解决方案:

    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)
    ...
    

    【讨论】:

      猜你喜欢
      • 2012-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-29
      • 1970-01-01
      相关资源
      最近更新 更多