api.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:Saylua 作者: LikeMyBread 项目源码 文件源码
def image(base, items):
    items = items.split(',')

    # This will be replaced with calls to the database later
    base = os.path.join(app.static_folder, 'img/avatar/m.png')
    image_url_base = os.path.join(app.static_folder, 'img/avatar')
    item_images = os.listdir(image_url_base)

    result = Image.open(base, 'r')
    for i in items:
        if i.isdigit():
            i = int(i)
        if i >= 0 and i < len(item_images):
            image_url = os.path.join(image_url_base, item_images[i])
            if imghdr.what(image_url) == 'png':
                # Stack the image on top of the current result
                curr_image = Image.open(image_url, 'r')

                # Third parameter is a mask used to preserve alpha
                result.paste(curr_image, (0, 0), curr_image)

    return serve_pil_image(result)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号