TiffTag¶
- final class tifffile.TiffTag(parent, offset, code, dtype, count, value, valueoffset, /)¶
TIFF tag structure.
TiffTag instances are not thread-safe. All attributes are read-only.
- Parameters:
parent (TiffFile | TiffWriter) – TIFF file tag belongs to.
offset (int) – Position of tag structure in file.
code (int) – Decimal code of tag.
dtype (DATATYPE | int) – Data type of tag value item.
count (int) – Number of items in tag value.
valueoffset (int) – Position of tag value in file.
value (Any)
- parent: TiffFile | TiffWriter¶
TIFF file tag belongs to.
- offset: int¶
Position of tag structure in file.
- code: int¶
Decimal code of tag.
- count: int¶
Number of items in tag value.
- valueoffset: int¶
Position of tag value in file.
- classmethod fromfile(parent, /, *, offset=None, header=None, validate=True)¶
Return TiffTag instance from file.
- Parameters:
parent (TiffFile) – TiffFile instance tag is read from.
offset (int | None) – Position of tag structure in file. The default is the position of the file handle.
header (bytes | None) – Tag structure as bytes. The default is read from the file.
validate (bool) – Raise TiffFileError if data type or value offset are invalid.
- Raises:
TiffFileError – Data type or value offset are invalid and validate is True.
- Return type:
- property value: Any¶
Value of tag, delay-loaded from file if necessary.
- property dtype_name: str¶
Name of data type of tag value.
- property name: str¶
Name of tag from
_TIFF.TAGS
registry.
- property dataformat: str¶
Data type as struct.pack format.
- property valuebytecount: int¶
Number of bytes of tag value in file.
- astuple()¶
Return tag code, dtype, count, and encoded value.
The encoded value is read from file if necessary.
- Return type:
TagTuple
- overwrite(value, /, *, dtype=None, erase=True)¶
Write new tag value to file and return new TiffTag instance.
Warning: changing tag values in TIFF files might result in corrupted files or have unexpected side effects.
The packed value is appended to the file if it is longer than the old value. The file position is left where it was.
Overwriting tag values in NDPI files > 4 GB is only supported if single integer values and new offsets do not exceed the 32-bit range.
- Parameters:
value (Any) – New tag value to write. Must be compatible with the struct.pack formats corresponding to the tag’s data type.
dtype (DATATYPE | int | str | None) – New tag data type. By default, the data type is not changed.
erase (bool) – Overwrite previous tag values in file with zeros.
- Raises:
struct.error – Value is not compatible with dtype or new offset exceeds TIFF size limit.
ValueError – Invalid value or dtype, or old integer value in NDPI files exceeds 32-bit range.
- Return type: