How do I programmatically check whether an image (PNG, JPEG, or GIF) is corrupted?

前端 未结 5 1736
你的背包
你的背包 2020-12-13 10:40

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 kno

5条回答
  •  不思量自难忘°
    2020-12-13 11:06

    If your exact requirements are that it show correctly in FireFox you may have a difficult time - the only way to be sure would be to link to the exact same image loading source code as FireFox.

    Basic image corruption (file is incomplete) can be detected simply by trying to open the file using any number of image libraries.

    However many images can fail to display simply because they stretch a part of the file format that the particular viewer you are using can't handle (GIF in particular has a lot of these edge cases, but you can find JPEG and the rare PNG file that can only be displayed in specific viewers). There are also some ugly JPEG edge cases where the file appears to be uncorrupted in viewer X, but in reality the file has been cut short and is only displaying correctly because very little information has been lost (FireFox can show some cut off JPEGs correctly [you get a grey bottom], but others result in FireFox seeming the load them half way and then display the error message instead of the partial image)

提交回复
热议问题