如何检测jpg jpeg图像文件是否损坏(不完整)? [英] How to detect if the jpg jpeg image file is corrupted(incomplete)?

查看:462
本文介绍了如何检测jpg jpeg图像文件是否损坏(不完整)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在我的网站上显示来自其他人的图像服务器的某些图像,但是来自图像服务器的某些图像只能部分显示,如下面的图像

I have to show some images from others' image server on my website but some of the images from the image server can only partially show like below image

图像包含宽度和高度信息,但仅显示图像的顶部.如果我使用Chrome v61打开图像,则如下图所示

The image included width and height info but only show very top part of image. If I open the image with Chrome v61, it looks like below image

Chrome v61显示此颜色以在png图像文件中呈现透明性,但是在jpg jpeg图像文件中是什么意思?

Chrome v61 shows this color to present the transparency in png image file but what does it mean in jpg jpeg image file?

有人知道如何检测这种损坏(不完整)的图像吗?我试图避免在我的网站上显示此类图像.

Is there anyone knows how to detect this kind of corrupted(incomplete) image? I'm trying to aviod this kind of images showing on my website.

推荐答案

如果您需要编程的"方法而不是@MarkSetchell建议的命令行方法,则几乎可以在任何编程中为此创建一个非常快速的测试语言. 请注意,这只会找到您在问题中提到的那种截断腐败行为. Mark的方法通常可以更可靠地发现腐败行为.

If you need a "programmatic" approach rather than the command line approach suggested by @MarkSetchell, you could create a very quick test for this in pretty much any programming language. Note that this will only find the kind of truncating corruption you mention in your question. Mark's method may be more reliable for finding corruption in general.

我们知道,任何JPEG文件或流都是根据 JPEG交换格式编写的.这意味着它们必须以SOI(图像开始)标记(两个字节0xFF, 0xD8)开始,并以EOI(图像结束)标记(两个字节,0xFF, 0xD9)结束.在JPEG文件/流中的其他任何地方都找不到这两个标记.

As we know, any JPEG file or stream is written according to the JPEG Interchange Format. That means that they must start with a SOI (Start-of-Image) marker (the two bytes 0xFF, 0xD8) and end with the EOI (End-of-Image) marker (two bytes, 0xFF, 0xD9). These two markers will not be found anywhere else in a JPEG file/stream.

如果首先通过检查前两个字节并与SOI标记匹配将文件标识为JPEG,则可以跳到末尾并向后搜索EOI标记.最有可能的是,这要么是最后两个字节,要么根本找不到它们.但是进行搜索可能更安全(可能是有限的长度),因为我认为可以将应用程序特定的数据放在EOI之后的JPEG文件中(如果我输入错了,请改正我的名字).

If you first identify the file as a JPEG by inspecting the first two bytes and matching against the SOI marker, you could skip to the end and search backwards for the EOI marker. Most likely, this will either be the last two bytes or you will not find them at all. But it may be safer to do a search (perhaps for a limited length), as I think it may be allowed to place application-specific data in a JPEG file after the EOI (someone, please correct me if I'm wrong).

这篇关于如何检测jpg jpeg图像文件是否损坏(不完整)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆