您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

如何在Python中将图像拆分成多个片段

如何在Python中将图像拆分成多个片段

from PIL import Image

def crop(path, input, height, width, k, page, area):
    im = Image.open(input)
    imgwidth, imgheight = im.size
    for i in range(0,imgheight,height):
        for j in range(0,imgwidth,width):
            @R_181_2419@ = (j, i, j+width, i+height)
            a = im.crop(@R_181_2419@)
            try:
                o = a.crop(area)
                o.save(os.path.join(path,"PNG","%s" % page,"IMG-%s.png" % k))
            except:
                pass
            k +=1
python 2022/1/1 18:39:01 有272人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶