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

查看:24
本文介绍了如何检测 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天全站免登陆