如何以编程方式检查图像(PNG,JPEG或GIF)是否已损坏?

编程入门 行业动态 更新时间:2024-10-27 14:32:42
本文介绍了如何以编程方式检查图像(PNG,JPEG或GIF)是否已损坏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

好。所以我有大约250,000张高分辨率图像。我想要做的就是浏览所有这些并找到损坏的。如果您知道4scrape是什么,那么您就知道图像的本质了。

Okay. So I have about 250,000 high resolution images. What I want to do is go through all of them and find ones that are corrupted. If you know what 4scrape is, then you know the nature of the images I.

对我来说,损坏的是图像被加载到Firefox中它说

Corrupted, to me, is the image is loaded into Firefox and it says

无法显示图像此类图像,因为它包含错误。

现在,我可以选择所有250,000张图像(~150gb)并将它们拖放到Firefox中。那会很糟糕,因为我不认为Mozilla设计Firefox可以打开250,000个标签。不,我需要一种方法来以编程方式检查图像是否已损坏。

Now, I could select all of my 250,000 images (~150gb) and drag-n-drop them into Firefox. That would be bad though, because I don't think Mozilla designed Firefox to open 250,000 tabs. No, I need a way to programmatically check whether an image is corrupted.

有没有人知道PHP或Python库可以在这些方面做些什么?或者现有的Windows软件?

Does anyone know a PHP or Python library which can do something along these lines? Or an existing piece of software for Windows?

我已经删除了明显损坏的图像(例如0字节的图像)但是我有99.9%的确定那里在我的人群中漂浮着更多患病的图像。

I have already removed obviously corrupted images (such as ones that are 0 bytes) but I'm about 99.9% sure that there are more diseased images floating around in my throng of a collection.

推荐答案

一种简单的方法是尝试加载和验证文件使用PIL(Python成像库)。

An easy way would be to try loading and verifying the files with PIL (Python Imaging Library).

from PIL import Image v_image = Image.open(file) v_image.verify()

抓住例外......

Catch the exceptions...

来自文档:

im.verify()

尝试确定文件是否已损坏,实际上没有解码图像数据。如果此方法发现任何问题,则会引发适当的异常。此方法仅适用于新打开的图像;如果图像已加载,则结果未定义。此外,如果您需要在使用此方法后加载图像,则必须重新打开图像文件。

更多推荐

如何以编程方式检查图像(PNG,JPEG或GIF)是否已损坏?

本文发布于:2023-07-27 05:24:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1220596.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图像   方式   PNG   JPEG   GIF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!