Skip to content

Commit d20e250

Browse files
authored
Merge pull request #1 from radarhere/patch-1
Added Exif code examples
2 parents 074c6af + a8e03e4 commit d20e250

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

src/PIL/Image.py

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,7 +1433,7 @@ def get_value(element):
14331433

14341434
def getexif(self):
14351435
"""
1436-
Gets EXIF data of the image.
1436+
Gets EXIF data from the image.
14371437
14381438
:returns: an :py:class:`~PIL.Image.Exif` object.
14391439
"""
@@ -3607,18 +3607,36 @@ def _apply_env_variables(env=None):
36073607

36083608
class Exif(MutableMapping):
36093609
"""
3610-
Exif class provides read and write access to EXIF image data.
3610+
This class provides read and write access to EXIF image data::
36113611
3612-
Only basic information is available on the root level, in Exif object
3613-
itself. In order to access the rest, obtain their respective IFDs using
3614-
:py:meth:`~PIL.Image.Exif.get_ifd` method and one of
3615-
:py:class:`~PIL.ExifTags.IFD` members (most notably ``Exif`` and
3616-
``GPSInfo``).
3612+
from PIL import Image
3613+
im = Image.open("exif.png")
3614+
exif = im.getexif() # Returns an instance of this class
3615+
3616+
Information can be read and written, iterated over or deleted::
3617+
3618+
print(exif[274]) # 1
3619+
exif[274] = 2
3620+
for k, v in exif.items():
3621+
print("Tag", k, "Value", v) # Tag 274 Value 2
3622+
del exif[274]
3623+
3624+
To access information beyond IFD0, :py:meth:`~PIL.Image.Exif.get_ifd`
3625+
returns a dictionary::
3626+
3627+
from PIL import ExifTags
3628+
im = Image.open("exif_gps.jpg")
3629+
exif = im.getexif()
3630+
gps_ifd = exif.get_ifd(ExifTags.IFD.GPSInfo)
3631+
print(gps_ifd)
3632+
3633+
Other IFDs include ``ExifTags.IFD.Exif``, ``ExifTags.IFD.Makernote``,
3634+
``ExifTags.IFD.Interop`` and ``ExifTags.IFD.IFD1``.
3635+
3636+
:py:mod:`~PIL.ExifTags` also has enum classes to provide names for data::
36173637
3618-
Both root Exif and child IFD objects support dict interface and can be
3619-
indexed by int values that are available as enum members of
3620-
:py:class:`~PIL.ExifTags.Base`, :py:class:`~PIL.ExifTags.GPS`, and
3621-
:py:class:`~PIL.ExifTags.Interop`.
3638+
print(exif[ExifTags.Base.Software]) # PIL
3639+
print(gps_ifd[ExifTags.GPS.GPSDateStamp]) # '1999:99:99 99:99:99'
36223640
"""
36233641

36243642
endian = None

0 commit comments

Comments
 (0)