我正在尝试以 90 度旋转的方式操作 Base64 编码的图像。经过此操作,我想将其转换回 Base64 字符串。但不幸的是还无法实现这一目标。
这是我到目前为止所做的:
image_string = StringIO(base64.b64decode(base64_string_here))
image = Image.open(image_string)
angle = 90
rotated_image = image.rotate( angle, expand=1 )
请帮助我如何将此旋转图像转换为 base64 字符串。
这是dir()
旋转图像的:
['_Image__transformer', '__doc__', '__getattr__', '__init__',
'__module__'、'__repr__'、'_copy'、'_dump'、'_expand'、'_makeself'、
'_new', '类别', '转换', '复制', '裁剪', '草稿', '过滤器',
'格式','格式描述','fromstring','getbands','getbbox',
'getcolors','getdata','getextrema','getim','getpalette',
'getpixel','getprojection','直方图','im','信息','负载',
'模式','偏移','调色板','粘贴','点','putalpha','putdata',
'putpalette'、'putpixel'、'量化'、'只读'、'调整大小'、'旋转'、
“保存”、“查找”、“显示”、“大小”、“分割”、“讲述”、“缩略图”、
'tobitmap'、'tostring'、'变换'、'转置'、'验证']
Python 3
import base64
from io import BytesIO
buffered = BytesIO()
image.save(buffered, format="JPEG")
img_str = base64.b64encode(buffered.getvalue())
Python 2
import base64
import cStringIO
buffer = cStringIO.StringIO()
image.save(buffer, format="JPEG")
img_str = base64.b64encode(buffer.getvalue())
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)