tagkit.image.exif¶
EXIF image handling functionality.
This module provides classes for reading, modifying, and removing EXIF tags from image files.
Module Contents¶
Classes¶
Handler for reading, modifying, and removing EXIF tags from a single image file. |
API¶
- class tagkit.image.exif.ExifImage(file_path: tagkit.core.types.FilePath, tag_filter: Optional[Iterable[Union[int, str]]] = None, thumbnail: Optional[bool] = None, ifd: Optional[tagkit.core.types.IfdName] = None, io_backend: Optional[tagkit.tag_io.base.ExifIOBackend] = None)¶
Handler for reading, modifying, and removing EXIF tags from a single image file.
- Args:
file_path: Path to the image file. tag_filter: Optional list of tag names or IDs to filter by thumbnail: If True, use thumbnail IFD ifd: Specific IFD to use io_backend: Custom backend for EXIF IO. Defaults to piexif.
- Example:
>>> exif = ExifImage('image1.jpg') >>> exif.tags['Make'] ExifTag(id=271, value='Tagkit', ifd='IFD0')
Initialization
- __len__() int¶
Return the number of tags in this image.
- write_tag(tag: Union[str, int], value: tagkit.core.types.TagValue, ifd: Optional[tagkit.core.types.IfdName] = None)¶
Set the value of a specific EXIF tag.
- Args:
tag: Tag name or tag ID. value: Value to set. ifd: Specific IFD to use.
- Raises:
KeyError: If the tag is not found. ValueError: If the tag or IFD is invalid.
- Example:
>>> exif = ExifImage('image1.jpg') >>> exif.write_tag('Artist', 'John Doe', ifd='IFD0')
- write_tags(tags: dict[Union[str, int], tagkit.core.types.TagValue], ifd: Optional[tagkit.core.types.IfdName] = None)¶
Set multiple EXIF tags at once.
- Args:
tags: A dictionary mapping tag names or IDs to values. ifd: Specific IFD to use for all tags (overrides default logic).
- Example:
>>> exif = ExifImage('image1.jpg') >>> exif.write_tags({'Artist': 'Jane', 'Copyright': '2025 John'})
- delete_tag(tag_key: Union[str, int], ifd: Optional[tagkit.core.types.IfdName] = None)¶
Remove a specific EXIF tag if it exists.
- Args:
tag_key: Tag name or tag ID. ifd: Specific IFD to use.
- Raises:
ValueError: If the tag or IFD is invalid.
- Example:
>>> exif = ExifImage('image10.jpg') >>> exif.delete_tag('Make', ifd='IFD0')
- delete_tags(tags: list[Union[str, int]], ifd: Optional[tagkit.core.types.IfdName] = None)¶
Remove multiple EXIF tags at once.
- Args:
tags: A list of tag names or tag IDs to remove. ifd: Specific IFD to use for all tags (overrides default logic).
- Example:
>>> exif = ExifImage('image1.jpg') >>> exif.delete_tags(['Artist', 'Copyright'])
- property tags: dict[str, tagkit.core.tag.ExifTag]¶
Get the filtered tags based on tag_filter and ifd settings.
- Returns:
dict: A dictionary of filtered tags with tag names as keys.
- save(create_backup: bool = False)¶
Write the modified EXIF data back to the image file.
- Raises:
IOError: If writing to the file fails.
- as_dict(binary_format: Optional[str] = None) dict[str, dict[str, Union[str, int]]]¶
Convert the image data to a nested dictionary structure.
- Args:
- binary_format: How to format binary data - ‘bytes’, ‘hex’, or ‘base64’
If None, <bytes: N> will be shown as a placeholder.
- Returns:
dict: A nested dictionary containing the EXIF data for the image.
- Example:
>>> exif = ExifImage('image2.jpg') >>> exif.as_dict() {'Make': {'id': 271, 'value': 'Tagkit', 'ifd': 'IFD0'}}