如何在Python中将save_base64转换为图像 [英] How to Convert save_base64 to Image in Python

查看:741
本文介绍了如何在Python中将save_base64转换为图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码下载带有查询字符串的图像,这没有任何问题.

I use code as below to download Image with query string, it is no any problems.

urlServer = "http://ipcamera-viewer.com/image/?p=199619_20170221_162149_7208.jpg"
browser.get(urlServer)
imgData = browser.get_screenshot_as_base64()
size = int(len(imgData) * 0.75)
if size > minSizeImage:
    browser.save_screenshot(pathLocal)

现在我想旋转图像,然后再保存到文件中,我可以使用代码

now I want to rotate the image before save to file, can I use code

urlServer = "http://ipcamera-viewer.com/image/?p=199619_20170221_162149_7208.jpg"
browser.get(urlServer)
imgBase64= browser.get_screenshot_as_base64()
imgBytes = BytesIO(base64.b64decode(imgBase64))
imgData = PIL.Image.open(imgBytes)
size = int(len(imgBase64) / 8)
if size > minSizeImage:
    imgData = imgData.rotate(angle, expand = True)
    imgData.save(pathLocal)

推荐答案

这种方法应该可以解决问题,而不是保存以便再次阅读.没机会尝试一下.

Something like this should do the trick, rather then saving just to read it in again. Didn't get the chance to try this out though.

from PIL import Image
from io import BytesIO
import base64


im = Image.open(BytesIO(base64.b64decode(imgData)))
im = im.rotate(45)
im.save(pathLocal)

这篇关于如何在Python中将save_base64转换为图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆