Use exiv2 or imagemagick to remove EXIF data from stdin and output to stdout

淺唱寂寞╮ 提交于 2019-12-22 12:22:33

问题


How can I pipe an image into exiv2 or imagemagick, strip the EXIF tag, and pipe it out to stdout for more manipulation?

I'm hoping for something like:

exiv2 rm - - | md5sum

which would output an image supplied via stdin and calcualte its md5sum.

Alternatively, is there a faster way to do this?


回答1:


Using exiv2

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

Using ImageMagick

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

Using exiftool

ExifTool by Phil Harvey

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.

Conclusion

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.




回答2:


I tested with NEF file. Seems only exiv2 rm works best. exiftool and convert can't remove all metadata from .nef FILE.

Notice that the output file of exiv2 rm can no longer be displayed by most image viewers. But I only need the MD5 hash keeps same after I update any metadata of the .NEF file. It works perfect for me.



来源:https://stackoverflow.com/questions/23984963/use-exiv2-or-imagemagick-to-remove-exif-data-from-stdin-and-output-to-stdout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!