如何将图像通过管道传输到 exiv2 或 imagemagick,剥离 EXIF 标签,然后将其传输到标准输出以进行更多操作?
我希望有类似的东西:
exiv2 rm - - | md5sum
这将输出通过标准输入提供的图像并计算其 md5sum。
或者,有没有更快的方法来做到这一点?
如何将图像通过管道传输到 exiv2 或 imagemagick,剥离 EXIF 标签,然后将其传输到标准输出以进行更多操作?
我希望有类似的东西:
exiv2 rm - - | md5sum
这将输出通过标准输入提供的图像并计算其 md5sum。
或者,有没有更快的方法来做到这一点?
I was not able to find a way to get exiv2
to output to stdout
-- it only wants to overwrite the existing file. You could use a small bash
script to make a temporary file and get the md5 hash of that.
image.sh:
#!/bin/bash
cat <&0 > tmp.jpg # Take input on stdin and dump it to temp file.
exiv2 rm tmp.jpg # Remove EXIF tags in place.
md5sum tmp.jpg # md5 hash of stripped file.
rm tmp.jpg # Remove temp file.
You would use it like this:
cat image.jpg | image.sh
You can do this using ImageMagick instead by using the convert
command:
cat image.jpg | convert -strip - - | md5sum
Caveat:
I found that stripping an image of EXIF tags using convert
resulted in a smaller file-size than using exiv2
. I don't know why this is and what exactly is done differently by these two commands.
From man exiv2
:
rm Delete image metadata from the files.
From man convert
:
-strip strip image of all profiles and comments
You could use exiftool
(I got the idea from https://stackoverflow.com/a/2654314/3565972):
cat image.jpg | exiftool -all= - -out - | md5sum
This too, for some reason, produces a slightly different image size from the other two.
Needless to say, all three methods (exiv2
, convert
, exiftool
) produce outputs with different md5 hashes. Not sure why this is. But perhaps if you pick a method and stick to it, it will be consistent enough for your needs.
我用NEF文件测试过。似乎只有 exiv2 rm 效果最好。exiftool
并且convert
无法从 .nef 文件中删除所有元数据。
exiv2 rm
请注意,大多数图像查看器无法再显示的输出文件。但是我只需要在更新 .NEF 文件的任何元数据后保持 MD5 哈希值不变。它对我来说很完美。