【问题标题】:Can't get every exif data from tif-file无法从 tif 文件中获取所有 exif 数据
【发布时间】:2021-09-24 15:35:06
【问题描述】:

我正在尝试获取 tif 文件的标题和主题,但似乎我并没有获取所有数据。我正在寻找“Titel”和“Betreff”(我猜是英文“title”和“subject”)。这些值是否隐藏在 XPTitle、XPData 或 XPSubject 中?如果有,如何获取数据?

我尝试关注另一个主题:

    import exifread
    # Open image file for reading (binary mode)
    f = open(tif, 'rb')

    # Return Exif tags
    tags = exifread.process_file(f)

    # Print the tag/ value pairs
    for tag in tags.keys():
        if tag not in ('JPEGThumbnail', 'TIFFThumbnail', 'Filename', 'EXIF MakerNote'):
            print ("Key: %s, value %s" % (tag, tags[tag]))

我得到了什么:

Key: Image ImageWidth, value 967
Key: Image ImageLength, value 979
Key: Image BitsPerSample, value 32
Key: Image Compression, value Uncompressed
Key: Image PhotometricInterpretation, value 1
Key: Image Make, value XXXXXX
Key: Image StripOffsets, value 406
Key: Image SamplesPerPixel, value 1
Key: Image StripByteCounts, value 3786772
Key: Image XResolution, value 100
Key: Image YResolution, value 100
Key: Image PlanarConfiguration, value 1
Key: Image XPosition, value 4294967295/42579232
Key: Image YPosition, value 858993459/9308555
Key: Image ResolutionUnit, value Pixels/Centimeter
Key: Image Software, value XXXXXX
Key: Image SampleFormat, value Float
Key: Image XPTitle, value [70, 0, 108, 0, 117, 0, 111, 0, 114, 0, 101, 0, 115, 0, 122, 0, 101, 0, 110, 0, 122, 0, 0, 0]
Key: Image XPComment, value [0, 0]
Key: Image XPSubject, value [50, 0, 48, 0, 32, 0, 37, 0, 59, 0, 32, 0, 49, 0, 48, 0, 48, 0, 32, 0, ... ]

运行 exiftool 后,我知道数据在 XP 主题中。有什么想法可以在 python 中获取纯文本吗?

ExifTool Version Number         : 12.29
File Name                       : 01_Fluo.tif
Directory                       : .
File Size                       : 3.6 MiB
File Modification Date/Time     : 2021:07:06 11:06:04+02:00
File Access Date/Time           : 2021:07:15 21:05:56+02:00
File Creation Date/Time         : 2021:07:10 01:49:54+02:00
File Permissions                : -rw-rw-rw-
File Type                       : TIFF
File Type Extension             : tif
MIME Type                       : image/tiff
Exif Byte Order                 : Little-endian (Intel, II)
Image Width                     : 967
Image Height                    : 979
Bits Per Sample                 : 32
Compression                     : Uncompressed
Photometric Interpretation      : BlackIsZero
Make                            : XXXXX
Strip Offsets                   : 406
Samples Per Pixel               : 1
Strip Byte Counts               : 3786772
X Resolution                    : 100
Y Resolution                    : 100
Planar Configuration            : Chunky
X Position                      : 100.8700038
Y Position                      : 92.28000039
Resolution Unit                 : cm
Software                        : XXXXX
Sample Format                   : Float
XP Title                        : I NEED THIS AS STRING (Company Name)
XP Comment                      :
XP Subject                      : AND THIS AS STRING (20 %; 100 mW)
Image Size                      : 967x979
Megapixels                      : 0.947

【问题讨论】:

  • 在文件上运行exiftool,它将准确地告诉您其中的内容以及 XMP、EXIF、IPTC 还是其他方式。
  • 好的,这有帮助。现在我知道它在 XP 主题中。我可以用python以某种方式阅读吗?
  • 也许在你的问题下点击edit并添加exiftool的输出,这样我们也可以看到......

标签: python-3.x windows tiff exif


【解决方案1】:
convString = tags["Image XPSubject"].values
convString = [x for x in convString if x != 0]
s = "".join([chr(c) for c in convString])

XPSubject、XPComment 和 XPTitle 只是其中包含 ASCII 代码的列表。所以,过滤零后,上面的代码解决了我的问题。

【讨论】:

    猜你喜欢
    • 2018-01-18
    • 1970-01-01
    • 2013-10-25
    • 1970-01-01
    • 2015-12-14
    • 2010-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多