【问题标题】:Upload Resized Image To Imgur Without Saving On Disk将调整大小的图像上传到 Imgur 而不保存在磁盘上
【发布时间】:2014-10-14 15:43:34
【问题描述】:

我正在编写一个脚本来调整图像大小,然后将其上传到 Imgur - 但我不想将图像保存在磁盘上!

fp = requests.get(link_of_image)
img = StringIO.StringIO(fp.content)
image = Image.open(img)
im2 = image.resize((50, 50), Image.ANTIALIAS)
temp = StringIO.StringIO()
im2.save(temp, 'png')
temp.seek(0)

j1 = requests.post(
    url,
    headers = headers,
    data = {
        'key': api_key,
        'image': temp.read(),
        'type': 'base64',
        'name': '1.png',
        'title': 'Picture no. 1'
    }
)

运行此脚本后,我收到错误Image format not supported, or image is corrupt

【问题讨论】:

    标签: python python-imaging-library imgur


    【解决方案1】:

    您的图片似乎不是 base64 编码的,请尝试更改:

        'image': temp.read(),
    

        'image': temp.read().encode("base64"),
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-07
      • 2016-06-20
      • 2011-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多