Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
45 lines (35 sloc) 1.16 KB
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Author: wxnacy(
# Description: 图片叠加
import io
from PIL import Image
import requests
def get_image(path):
'''通过地址获取 image 对象'''
image = None
if path.startswith('http'):
res = requests.get(path)
image =
image =
return image
def image2bytes(image):
img_bytes = io.BytesIO(), image.format)
return img_bytes.getvalue()
def overlay(big_path, small_path, width, height, small_thumbnail=()):
big_image = get_image(big_path)
small_image = get_image(small_path)
if small_thumbnail:
big_image.paste(small_image,(width, height)) # 显示图片
#'/Users/wxnacy/Downloads/pillow_overlay.png') # 保存
# 或者返回图片的二进制
return image2bytes(big_image)
if __name__ == "__main__":
'', 157, 45)
You can’t perform that action at this time.