Python判断图片是否破损的解决方法

      发布在:Python技术      评论:0 条评论

在使用python处理图片的时候,如果是破损有问题的图片文件通过Pillo打开的时候会报错,于是想到使⽤imghdr模块中的what()⽅法判断图⽚⽂件是否损坏,若⽂件损坏,则返回None,否则返回图⽚⽂件的类型,如jpeg等。imgh 内容⻅: https://docs.python.org/3/library/imghdr.html


import imghdr

check = imghdr.what(r'D:\tools20211107\1.jpg')
if check == None:
print('说明这张图片已经损坏')


相关文章
热门推荐