Skip to content

Commit

Permalink
Merge pull request #1 from radarhere/patch-1
Browse files Browse the repository at this point in the history
Added Exif code examples
  • Loading branch information
greatvovan committed Feb 12, 2023
2 parents 074c6af + a8e03e4 commit d20e250
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions src/PIL/Image.py
Expand Up @@ -1433,7 +1433,7 @@ def get_value(element):

def getexif(self):
"""
Gets EXIF data of the image.
Gets EXIF data from the image.
:returns: an :py:class:`~PIL.Image.Exif` object.
"""
Expand Down Expand Up @@ -3607,18 +3607,36 @@ def _apply_env_variables(env=None):

class Exif(MutableMapping):
"""
Exif class provides read and write access to EXIF image data.
This class provides read and write access to EXIF image data::
Only basic information is available on the root level, in Exif object
itself. In order to access the rest, obtain their respective IFDs using
:py:meth:`~PIL.Image.Exif.get_ifd` method and one of
:py:class:`~PIL.ExifTags.IFD` members (most notably ``Exif`` and
``GPSInfo``).
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::
Both root Exif and child IFD objects support dict interface and can be
indexed by int values that are available as enum members of
:py:class:`~PIL.ExifTags.Base`, :py:class:`~PIL.ExifTags.GPS`, and
:py:class:`~PIL.ExifTags.Interop`.
print(exif[ExifTags.Base.Software]) # PIL
print(gps_ifd[ExifTags.GPS.GPSDateStamp]) # '1999:99:99 99:99:99'
"""

endian = None
Expand Down

0 comments on commit d20e250

Please sign in to comment.