TOC

Linux 工具箱: exiftool

安装

sudo apt install -y libimage-exiftool-perl

常用命令

# 查看 Exif 信息:
exiftool      media/images/django.jpg
exiftool -X   media/images/django.jpg  # XML 格式
exiftool -csv media/images/django.jpg  # CSV 格式

exiftool    media/images/
exiftool -r media/images/  # 递归遍历子目录

# 清除文件 Exif 信息:
exiftool -all= -overwrite_original media/images/django.jpg
exiftool -all= -overwrite_original media/images/
exiftool -all= -overwrite_original -ext png media/images/

# 清除指定 Exif 信息
exiftool -gps:all= *.jpg

关于 Exif

日本公司创造一项标准,为图片添加一些附加数据,比如相机的品牌型号,拍摄时的地理位置,光圈,曝光度等信息。

ITEM Notes
ApertureValue -
Artist -
BitsPerSample -
BrightnessValue -
ColorSpace -
ComponentsConfiguration -
CompressedBitsPerPixel -
Contrast -
Copyright -
CustomRendered -
DateTime -
DateTimeDigitized -
DateTimeOriginal -
DigitalZoomRatio -
ExifImageLength -
ExifImageWidth -
ExifOffset -
ExifVersion -
ExposureBiasValue -
ExposureMode -
ExposureProgram -
ExposureTime -
FileSource -
Flash -
FlashPixVersion -
FNumber -
FocalLength -
FocalLengthIn35mmFilm -
FocalPlaneResolutionUnit -
FocalPlaneXResolution -
FocalPlaneYResolution -
GainControl -
GPSAltitude -
GPSAltitudeRef -
GPSDateStamp -
GPSInfo -
GPSLatitude -
GPSLatitudeRef -
GPSLongitude -
GPSLongitudeRef -
GPSProcessingMethod -
GPSTimeStamp -
ImageDescription -
ImageLength -
ImageWidth -
InteroperabilityOffset -
LensMake -
LensModel -
LensSpecification -
LightSource -
Make -
MakerNote -
MaxApertureValue -
MeteringMode -
Model -
OffsetTime -
OffsetTimeDigitized -
OffsetTimeOriginal -
Orientation -
PhotographicSensitivity -
PhotometricInterpretation -
PixelXDimension -
PixelYDimension -
PrintImageMatching -
ResolutionUnit -
SamplesPerPixel -
Saturation -
SceneCaptureType -
SceneType -
SensingMethod -
SensitivityType -
Sharpness -
ShutterSpeedValue -
Software -
SubjectArea -
SubjectDistanceRange -
SubSecTime -
SubSecTimeDigitized -
SubSecTimeOriginal -
thumbnail:BitsPerSample -
thumbnail:Compression -
thumbnail:ImageLength -
thumbnail:ImageWidth -
thumbnail:InteroperabilityIndex -
thumbnail:InteroperabilityVersion -
thumbnail:JPEGInterchangeFormat -
thumbnail:JPEGInterchangeFormatLength -
thumbnail:PhotometricInterpretation -
thumbnail:ResolutionUnit -
thumbnail:SamplesPerPixel -
thumbnail:XResolution -
thumbnail:YResolution -
WhiteBalance -
WinXP-Author -
WinXP-Subject -
WinXP-Title -
XResolution -
YCbCrPositioning -
YResolution -

Python Exif 操作

import pprint
from PIL import Image, ExifTags
filepath = os.path.expanduser('~/Pictures/Photos/IMG_20180430_133154.jpg')
image = Image.open(filepath)
data_exif = image._getexif()
image.close()
data = {ExifTags.TAGS.get(k): v for k, v in data_exif.items()}
if 'GPSInfo' in data and isinstance(data['GPSInfo'], dict):
    data['GPSInfo'] = {ExifTags.GPSTAGS.get(k): v for k, v in data['GPSInfo'].items()}
pprint.pprint(data)

参考资料与拓展阅读