Deprecated: parse_url(): Passing null to parameter #1 ($url) of type string is deprecated in /www/wwwroot/blog_qqvbc_com/usr/plugins/Access/Access_Core.php on line 339

Deprecated: parse_url(): Passing null to parameter #1 ($url) of type string is deprecated in /www/wwwroot/blog_qqvbc_com/usr/plugins/Access/Access_Core.php on line 392

Deprecated: parse_url(): Passing null to parameter #1 ($url) of type string is deprecated in /www/wwwroot/blog_qqvbc_com/usr/plugins/Access/Access_Core.php on line 394
python缩放图片再居中剪切 - Joyber 的博客

import io, requests
from PIL import Image

url = 'https://cdn.tatlerasia.com/asiatatler/i/hk/2018/11/05194216-hennessey-venom-f5-15_cover_1600x1000.jpg'
res = requests.get(url)

img = Image.open(io.BytesIO(res.content))

def imageCut(img:Image, flag='center'):
    '''居中剪切成正方形图片'''
    # 计算剪切图片的坐标点,左上角和右下角坐标
    (w, h) = img.size
    if w > h:
        opt = ((w-h)/2,0,(w-h)/2+h,h)
    else:
        opt = (0, (h-w)/2,w,(h-w)/2+w)
    return img.crop(opt)

img = imageCut(img)

标签: none

添加新评论