现在我的代码写PNG,但我不能打开它-错误的文件。 没有低声的所有作品,但我需要裁剪png文件。用我的坐标(没有PIL-box)和透明图像。在
Image.open(imagefile)
#image = image.crop(crop_coords) #only work without cropping
image.thumbnail([x, y], Image.ANTIALIAS)
imagefile = StringIO()
imagefile = open(file_destination, 'w')
try:
image.save(imagefile, "PNG", quality=90)
except:
print "Cannot save user image"
谢谢你的帮助。在
我注意到这个问题只存在于png文件和索引png alpha图像。在
您必须以二进制模式打开该文件,否则它将写入某些内容,但文件可能已损坏。根据您所做的测试,文件是否会损坏,这可能不是因为裁剪本身。在
以下是我制作的工作版本:
感谢您: PIL does not save transparency
这里有一个简单的解决方案,使用纽比和枕头,只要改变你自己的坐标问号!在
相关问题 更多 >
编程相关推荐