Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add description for getexif() and Exif #6930

Merged
merged 6 commits into from Feb 12, 2023
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/PIL/Image.py
Expand Up @@ -1432,6 +1432,11 @@ def get_value(element):
return {get_name(root.tag): get_value(root)}

def getexif(self):
"""
Gets EXIF data from the image.

:returns: an :py:class:`~PIL.Image.Exif` object.
"""
if self._exif is None:
self._exif = Exif()
self._exif._loaded = False
Expand Down Expand Up @@ -3601,6 +3606,39 @@ def _apply_env_variables(env=None):


class Exif(MutableMapping):
"""
This class provides read and write access to EXIF image data::

from PIL import Image
im = Image.open("exif.png")
exif = im.getexif() # Returns an instance of this class

Information can be read and written, iterated over or deleted::

print(exif[274]) # 1
exif[274] = 2
for k, v in exif.items():
print("Tag", k, "Value", v) # Tag 274 Value 2
del exif[274]

To access information beyond IFD0, :py:meth:`~PIL.Image.Exif.get_ifd`
returns a dictionary::

from PIL import ExifTags
im = Image.open("exif_gps.jpg")
exif = im.getexif()
gps_ifd = exif.get_ifd(ExifTags.IFD.GPSInfo)
print(gps_ifd)

Other IFDs include ``ExifTags.IFD.Exif``, ``ExifTags.IFD.Makernote``,
``ExifTags.IFD.Interop`` and ``ExifTags.IFD.IFD1``.

:py:mod:`~PIL.ExifTags` also has enum classes to provide names for data::

print(exif[ExifTags.Base.Software]) # PIL
print(gps_ifd[ExifTags.GPS.GPSDateStamp]) # '1999:99:99 99:99:99'
radarhere marked this conversation as resolved.
Show resolved Hide resolved
"""

endian = None
bigtiff = False

Expand Down