thumbnail_processors.py 文件源码

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

项目:gougo 作者: amaozhao 项目源码 文件源码
def whitespace(image, size, whitespace=False, whitespace_color=None, **kwargs):
    if not whitespace:
        return image

    if whitespace_color is None:
        whitespace_color = FILER_WHITESPACE_COLOR
    if whitespace_color is None:
        whitespace_color = '#fff'

    old_image = image
    source_x, source_y = image.size
    target_x, target_y = size

    image = Image.new('RGBA', (target_x, target_y), whitespace_color)
    if source_x < target_x and source_y < target_y:  # whitespace all around
        image.paste(old_image, (
            (target_x - source_x) / 2, (target_y - source_y) / 2))
    elif source_x < target_x:  # whitespace on top and bottom only
        image.paste(old_image, ((target_x - source_x) / 2, 0))
    elif source_y < target_y:  # whitespace on sides only
        image.paste(old_image, (0, (target_y - source_y) / 2))
    else:  # no whitespace needed
        image = old_image

    return image
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号