简体   繁体   English

无论如何(命令行工具)计算.NEF(也.CR2,.TIFF)的MD5哈希,无论任何元数据?

[英]Is there anyway (commandline tools) to calculate MD5 hash for .NEF (also .CR2, .TIFF) regardless any metadata?

Is there anyway (commandline tools) to calculate MD5 hash for .NEF (also .CR2, .TIFF) regardless any metadata, eg EXIF, IPTC, XMP and so on? 无论如何(命令行工具)计算.NEF(也.CR2,.TIFF)的MD5哈希,无论是否有任何元数据,例如EXIF,IPTC,XMP等等?

The MD5 hash should be same once we update any metadata inside the image file. 一旦我们更新图像文件中的任何元数据,MD5哈希应该是相同的。

I searched for a while, the closest solution is: 我搜索了一会儿,最接近的解决方案是:

exiftool test.nef -all= -o - -m | md5

but 'exiftool -all=' still keeps a set of EXIF tags in the output file. 但'exiftool -all ='仍然在输出文件中保留一组EXIF标记。 The MD5 hash can be changed if I update remaining tags. 如果我更新剩余的标签,可以更改MD5哈希。

ImageMagick has a method for doing exactly this. ImageMagick有一种方法可以做到这一点。 It is installed on most Linux distros and is available for OSX (ideally via homebrew ) and also Windows. 它安装在大多数Linux发行版上,可用于OSX(理想情况下通过homebrew )和Windows。 There is an escape for the image signature which includes only pixel data and not metadata - you use it like this: image signature有一个转义,它只包含像素数据而不包含元数据 - 您可以像这样使用它:

identify -format %# _DSC2007.NEF
feb37d5e9cd16879ee361e7987be7cf018a70dd466d938772dd29bdbb9d16610

I know it does what you want and that the calculated checksum does not change when you modify the metadata on PNG files for example, and I know it does calculate the checksum correctly for CR2 and NEF files. 我知道它可以做你想要的,并且当你修改PNG文件上的元数据时计算的校验和不会改变,我知道它确实为CR2NEF文件正确计算了校验和。 However, I am not in the habit of modifying RAW files such as you have and have not tested it does the right thing in that case - though I would be startled if it didn't! 但是,我不习惯修改你所拥有的RAW文件,并且没有测试过它在这种情况下是正确的 - 尽管如果不这样做我会感到震惊! So please test before use. 所以请在使用前进行测试。

The reason that there is still some Exif data left is because the image data for a NEF file (and similar TIFF based filetypes) is located within that Exif block. 仍然存在一些Exif数据的原因是因为NEF文件的图像数据(以及类似的基于TIFF的文件类型)位于该Exif块内。 Remove that and you have removed the image data. 删除它,您已删除图像数据。 See ExifTool FAQ 7 , which has an example shortcut tag that may help you out. 请参阅ExifTool FAQ 7 ,其中包含可帮助您解决的示例快捷方式标记。

I assume your intention is to verify the actual image data has not been tampered with. 我假设您的目的是验证实际图像数据是否未被篡改。
An alternate approach to stripping the meta-data can be to convert the image to a format that has no metadata. 剥离元数据的另一种方法是将图像转换为没有元数据的格式。
ImageMagick is a well known open source (Apache 2 license) for image manipulation and conversion. ImageMagick是一个众所周知的开源(Apache 2许可证),用于图像处理和转换。 It provides libraries with various language bindings as well as command line tools for various operating systems. 它为各种语言绑定提供了库,并为各种操作系统提供了命令行工具。

You could try: 你可以尝试:

convert test.nef bmp:- | md5

This converts test.nef to bmp on stdout and pipes it to md5. 这会将test.nef转换为stdout上的bmp并将其传递给md5。
AFAIR bmp has no support for metadata and I'm not sure if ImageMagick even preserves metadata across conversions. AFAIR bmp不支持元数据,我不确定ImageMagick是否甚至在转换中保留元数据。
This will only work with single image files (ie not multi-image tiff or gif animations). 这仅适用于单个图像文件(即不是多图像tiff或gif动画)。 There is also the slight possibility some changes can be made to the image which result in the same conversion because of color space conversions, but these changes would not be visible. 还可能会对图像进行一些更改,因为颜色空间转换会导致相同的转换,但这些更改将不可见。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM