mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-04 21:50:54 +03:00
Make _getexif a function
This commit is contained in:
parent
666a3f7642
commit
c46b3fe256
|
@ -359,51 +359,55 @@ class JpegImageFile(ImageFile.ImageFile):
|
||||||
self.tile = []
|
self.tile = []
|
||||||
|
|
||||||
def _getexif(self):
|
def _getexif(self):
|
||||||
# Extract EXIF information. This method is highly experimental,
|
return _getexif(self)
|
||||||
# and is likely to be replaced with something better in a future
|
|
||||||
# version.
|
|
||||||
from PIL import TiffImagePlugin
|
def _getexif(self):
|
||||||
import io
|
# Extract EXIF information. This method is highly experimental,
|
||||||
def fixup(value):
|
# and is likely to be replaced with something better in a future
|
||||||
if len(value) == 1:
|
# version.
|
||||||
return value[0]
|
from PIL import TiffImagePlugin
|
||||||
return value
|
import io
|
||||||
# The EXIF record consists of a TIFF file embedded in a JPEG
|
def fixup(value):
|
||||||
# application marker (!).
|
if len(value) == 1:
|
||||||
try:
|
return value[0]
|
||||||
data = self.info["exif"]
|
return value
|
||||||
except KeyError:
|
# The EXIF record consists of a TIFF file embedded in a JPEG
|
||||||
return None
|
# application marker (!).
|
||||||
file = io.BytesIO(data[6:])
|
try:
|
||||||
head = file.read(8)
|
data = self.info["exif"]
|
||||||
exif = {}
|
except KeyError:
|
||||||
# process dictionary
|
return None
|
||||||
|
file = io.BytesIO(data[6:])
|
||||||
|
head = file.read(8)
|
||||||
|
exif = {}
|
||||||
|
# process dictionary
|
||||||
|
info = TiffImagePlugin.ImageFileDirectory(head)
|
||||||
|
info.load(file)
|
||||||
|
for key, value in info.items():
|
||||||
|
exif[key] = fixup(value)
|
||||||
|
# get exif extension
|
||||||
|
try:
|
||||||
|
file.seek(exif[0x8769])
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
info = TiffImagePlugin.ImageFileDirectory(head)
|
info = TiffImagePlugin.ImageFileDirectory(head)
|
||||||
info.load(file)
|
info.load(file)
|
||||||
for key, value in info.items():
|
for key, value in info.items():
|
||||||
exif[key] = fixup(value)
|
exif[key] = fixup(value)
|
||||||
# get exif extension
|
# get gpsinfo extension
|
||||||
try:
|
try:
|
||||||
file.seek(exif[0x8769])
|
file.seek(exif[0x8825])
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
info = TiffImagePlugin.ImageFileDirectory(head)
|
info = TiffImagePlugin.ImageFileDirectory(head)
|
||||||
info.load(file)
|
info.load(file)
|
||||||
for key, value in info.items():
|
exif[0x8825] = gps = {}
|
||||||
exif[key] = fixup(value)
|
for key, value in info.items():
|
||||||
# get gpsinfo extension
|
gps[key] = fixup(value)
|
||||||
try:
|
return exif
|
||||||
file.seek(exif[0x8825])
|
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
info = TiffImagePlugin.ImageFileDirectory(head)
|
|
||||||
info.load(file)
|
|
||||||
exif[0x8825] = gps = {}
|
|
||||||
for key, value in info.items():
|
|
||||||
gps[key] = fixup(value)
|
|
||||||
return exif
|
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
# stuff to save JPEG files
|
# stuff to save JPEG files
|
||||||
|
|
Loading…
Reference in New Issue
Block a user