N3RD/JN/dr_py/py/base64转图片.py

45 lines
150 KiB
Python
Raw Normal View History

2023-07-12 21:50:31 +08:00
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# File : base64转图片.py
# Author: DaShenHan&道长-----先苦后甜,任凭晚风拂柳颜------
# Date : 2022/12/9
import base64
import requests
from io import BytesIO
from PIL import Image
def main():
headers = {
'referer':'https://files.yuchenglw.com',
# 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36 Edg/108.0.1462.42'
}
r = requests.get('https://oa.qianyibangong.com/p/221121/33cb60d609',headers=headers,verify=False)
image_base64 = r.text
# print(r.text)
# print(type(image_base64))
a = """
data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAUDBAQEAwUEBAQFBQUGBwwIBwcHBw8LCwkMEQ8SEhEPERETFhwXExQaFRERGCEYGh0dHx8fExciJCIeJBweHx7/2wBDAQUFBQcGBw4ICA4eFBEUHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh7/wAARCAFoAk4DAREAAhEBAxEB/8QAHQAAAgIDAQEBAAAAAAAAAAAABQYEBwIDCAEACf/EAGIQAAIBAwMCBAQCBgYDCgkDFQECAwQFEQAGIRIxBxNBURQiYXEygQgVI0KRoTNSYrHB0RYkchcYQ1aCkpXS4fAlNDY3U6Kys7QJJkVjdHWj0/E1ZXOUVFVkd4OEk6S1w8T/xAAbAQACAwEBAQAAAAAAAAAAAAADBAECBQAGB//EAEQRAAEEAAQDBQcCBQMEAAYCAwEAAgMRBBIhMQVBURMiYXGBFJGhscHR8DLhBiMzQlIVYvE0coKSByQlQ6Ky0uI1U8L/2gAMAwEAAhEDEQA/AL/hHGfprOCZWmtuFFSyimmudvpajpEjLUSHKRnqwxA556Tj+PbRAxzhooBb/ciM0MlG0cdXVWtZZKdqhAawxdSIMuwDrwoBBJ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EMCrAlSGBBBBwQQexB4wdHSi3jtqilfa5cvvTXLl9rly+1y5dx0TRz08c8MiSRSIHjkQgqynsQexH115cBekSru2ezpuialnnqkrJaNAVjplmRZSmEJ+ZT+AqcZH4B6HlyP8ASgO3R3xGq7aklVVNP+2orZSKBJcEpB0TysuC5UkZCHkE
""".strip()
# a = image_base64
if ',' in a:
head,context=a.split(",")
else:
head = None
context = a
# 解码图片
img_data = base64.b64decode(context)
# imgdata = base64.b64decode(image_base64)
# print(imgdata)
# 将图片保存为文件
with open("苹果爱薇.jpg", 'wb') as f:
f.write(img_data)
image = Image.open(BytesIO(img_data))
image.show()
if __name__ == '__main__':
main()