<分区>
我有超过 2000 个来自网络摄像头流的图像(用于延时视频),我需要删除所有不完整和损坏的图像,然后再将它们传递给 php-gd 脚本,为最终视频编辑它们。
是否可以使用 imagemagick 或其他工具检测损坏的文件?如果我尝试用 feh 打开损坏的图像,它会在控制台中显示 libpng error: Read Error
提前致谢!
更新:在我的案例中,建议的识别方法似乎接受了不良图像。这是一个损坏的示例 http://imgur.com/YcB9n
<分区>
我有超过 2000 个来自网络摄像头流的图像(用于延时视频),我需要删除所有不完整和损坏的图像,然后再将它们传递给 php-gd 脚本,为最终视频编辑它们。
是否可以使用 imagemagick 或其他工具检测损坏的文件?如果我尝试用 feh 打开损坏的图像,它会在控制台中显示 libpng error: Read Error
提前致谢!
更新:在我的案例中,建议的识别方法似乎接受了不良图像。这是一个损坏的示例 http://imgur.com/YcB9n
最佳答案
试试 ImageMagick 的 identify
命令。从手册页:
Identify describes the format and characteristics of one or more image files. It will also report if an image is incomplete or corrupt.
示例:
$ identify foo.png
identify: NotAPNGImageFile (foo.png).
$ echo $?
1
另一种方法是使用 PIL(Python 图像库):
from PIL import Image
im = Image.open("foo.png")
im.verify()
来自documentation :
im.verify()
Attempts to determine if the file is broken, without actually decoding the image data. If this method finds any problems, it raises suitable exceptions. This method only works on a newly opened image; if the image has already been loaded, the result is undefined. Also, if you need to load the image after using this method, you must reopen the image file.
关于bash - 在 bash 脚本中检测损坏的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4780424/