Tyf

Bibliography

>>> import Tyf

TiffFile Objects

class TiffFile(list)

This class is is a list of all Image File Directories defining the TIFF file.

Arguments:

  • fileobj IO[AnyStr] - a python file object.
>>> tif = Tyf.open("test/CEA.tif")
>>> tif[0]["BitsPerSample"]
<IFD tag BitsPerSample:8>
>>> tif[0]["ModelTiepointTag"].value
(0.0, 0.0, 0.0, -28493.166784412522, 4255884.5438021915, 0.0)
>>> tr = tif[0].getModelTransformation()
>>> tr(0, 0)
(-28493.166784412522, 4255884.5438021915, 0.0, 1.0)
>>> tr(tif[0]["ImageWidth"], tif[0]["ImageLength"])
(2358.211624949061, 4224973.143255847, 0.0, 1.0)

gkd

shortcut to geokey directories

raster_loaded

True if raster data loaded

save

def save(f: Union[str, IO[AnyStr]],
         byteorder: str = "<",
         idx: int = None,
         ifd1: ifd.Ifd = None) -> None

Save object into a buffer.

Arguments:

  • f str|IO[AnyStr] - a valid file path or a python file object
  • byteorder string - ">" if big-endian used else "<"
  • idx int - IFD index to save
  • ifd1 ifd.Ifd - IFD to be used as thumbnail (only needed with JPEG saving)

JpegFile Objects

class JpegFile(list)

List of JPEG segment tuple (marker, segment) defining the JPEG file. Tyf manage to extract xmp data as python ElementTree object and EXIF data as IFD. ifd0 is a shortcut to JPEF Exif, ifd1 is a shortcut to JPEG Thumbnail and xmp is a shortcut to XMP data.

Arguments:

  • fileobj IO[AnyStr] - a python file object.
>>> jpg = Tyf.open("test/IMG_20150730_210115.jpg")
>>> jpg.ifd0["GPS IFD"]
<IFD tag GPS IFD:794>
>>> jpg.ifd0.get_location()
(5.1872093, 51.2095416, 0.0)
>>> jpg.xmp
<Element '{adobe:ns:meta/}xmpmeta' at 0x000001CA40C7C4A0>

ifd0

@property
def ifd0(obj)

Shortcut to JPEG EXIF data.

ifd1

@property
def ifd1(obj)

Shortcut to JPEG thumbnail.

xmp

@property
def xmp(obj)

Shortcut to XMP attribute.

__getitem__

def __getitem__(item: Union[int, str]) -> ifd.Tag

Arguments:

  • item int|str - tag number or key.

Returns:

  • ifd.Tag - ifd.Tag instance from ifd0.
>>> jpg["GPSLongitude"]
<IFD tag GPSLongitude:5.1872093>

get

def get(item: Union[int, str], default=None) -> ifd.Tag

Arguments:

  • item int|str - tag number or key.

Returns:

  • ifd.Tag - ifd.Tag instance from ifd1.
>>> jpg.get("ImageWidth")
<IFD tag ImageWidth:320>

set_xmp

def set_xmp(tag: str, value: str, **attributes) -> ET.SubElement

Set xmp tag value. Custom namespace can be used.

Arguments:

  • tag str - tag.
  • value str - tag value.
  • **attributes - all elements to be set using attributes arg on xml.etree.ElementTree.Element creation.

Returns:

  • xml.etree.ElementTree.Element - tag element.

get_xmp

def get_xmp(tag: str, ns: str = "EXIF") -> ET.Element

Get xmp tag value. Custom namespace can be used.

Arguments:

  • tag str - tag name.
  • ns url - xml namespace url (default value is http://ns.adobe.com/exif/1.0/).

Returns:

  • xml.etree.ElementTree.Element - tag element.

save

def save(f: Union[str, IO[AnyStr]]) -> None

Save object as a JPEG file. All segmet are writed in current order, only ifd0, ifd1 and xmp are recomputed.

Arguments:

  • f str|IO[AnyStr] - a valid file path or a python file object

save_thumbnail

def save_thumbnail(f: Union[str, IO[AnyStr]]) -> None

Save JPEG thumbnail in a separated TIFF or JPEG file, file extention automatically appended.

Arguments:

  • f str|IO[AnyStr] - a valid file path or a python file object

dump_exif

def dump_exif(f: Union[str, IO[AnyStr]]) -> None

Save EXIF data in a separated file. If f is a file object, it is not closed.

Arguments:

  • f buffer or string - a valid file path or a python file object

open

def open(f: Union[str, IO[AnyStr]]) -> Union[TiffFile, JpegFile]

Return JpegFile or TiffFile instance according to argument.

Arguments:

  • f str|IO[AnyStr] - a valid file path or a python file object.

Returns:

  • Tyf.JpegFile|Tyf.TiffFile - JPEG or TIFF instance.

Raises:

  • InvalidFileError - if file is neither a JPEG nor a TIFF file.