PIL返回黑色图像

时间:2018-03-29 07:55:08

标签: python image-processing pillow

我正在尝试将图像裁剪成几张小图像。我的代码保存了4张图片,但它们都是1kb的黑色方块。任何人都可以提出错误的建议吗?

from PIL import Image,ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True
import os.path

def slice(filename,desiredsize):
    name=filename.split('.')[0]
    img=Image.open('Myself.jpg')
    width,height=img.size
    nsamples=int(width/desiredsize)
    print img.size


    for i in range(nsamples):
        print "Creating slice: ", (i+1), "/", nsamples, "for", filename
        startpixel=i*desiredsize
        temp = img.crop((startpixel, 1, startpixel + desiredsize, desiredsize + 1))
        temp.save('C:\Users\lenovo\Documents\GitHub\\'+'{}_{}.jpg'.format(name,i))

slice('myself.jpg',100)

0 个答案:

没有答案