Tyf


>>> import Tyf

API

Because JPEG EXIF data are stored occording to TIFF specification, Tyf package is based on tag and Image file directory implementation.

Tag object

Let's see what is in Tag object :

>>> tag = Tyf.ifd.Tag("GPSLongitude")
>>> for k,v in sorted(tag.__dict__.items(), key=lambda e:e[0]):
...	print("%s: %r" %(k,v))
...
_Tag__types: [5]
_decoder: <function _0x2 at 0x02D046F0>
_encoder: <function _0x2 at 0x02D042B8>
comment: 'Indicates the longitude'
count: 3
key: 'GPSLongitude'
name: 'Orphan tag'
tag: 4
type: 5
value: (0, 1, 0, 1, 0, 1)
value_is_offset: True

Tag object automaticaly initiates all data it needs according to a given tag name. It uses _encoder and _decoder function to computes three different python values :

  1. scalar values (single one or tuple-ed ones)
  2. string object
  3. datetime object values

Value have to be changed using digest function and is recovered through decode one.

>>> tag
<Orphan tag 0x4: GPSLongitude = (0, 1, 0, 1, 0, 1)>
>>> tag.digest(10.321)
>>> tag.value
(10, 1, 19, 1, 78, 5)
>>> tag.decode()
10.321
>>> tag = Tyf.ifd.Tag(529)
>>> tag
<Orphan tag 0x211: YCbCrCoefficients = (299, 1000, 587, 1000, 114, 1000)>
>>> tag.digest((4.5,2.3,5.65))
>>> tag.value
(9, 2, 23, 10, 113, 20)
>>> tag.decode()
(4.5, 2.3, 5.65)

Note that a valid tag number can also be used on instanciation.

>>> tag = Tyf.ifd.Tag(37510)
>>> tag
<Orphan tag 0x9286: UserComment = b'ASCII\x00\x00\x00\x00'>
>>> tag.digest("Simple comment")
>>> tag.value
b'ASCII\x00\x00\x00Simple comment'
>>> tag.decode()
'Simple comment'
>>> import datetime
>>> tag = Tyf.ifd.Tag("DateTimeDigitized")
>>> tag
<Orphan tag 0x9004: DateTimeDigitized = b'\x00'>
>>> tag.digest(datetime.datetime(2016,12,20,9,10,0))
>>> tag
<Orphan tag 0x9004: DateTimeDigitized = b'2016:12:20 09:10:00\x00'>
>>> tag.decode()
datetime.datetime(2016, 12, 20, 9, 10)

Ifd object