mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 18:06:18 +03:00
Load EXIF from PNG where eXIf chunk is after first IDAT chunk
This commit is contained in:
parent
365d5e541a
commit
8ddcc1de52
BIN
Tests/images/exif.png
Normal file
BIN
Tests/images/exif.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 175 KiB |
|
@ -591,6 +591,21 @@ class TestFilePng(PillowTestCase):
|
||||||
self.assertEqual(im.text, {'TXT': 'VALUE', 'ZIP': 'VALUE'})
|
self.assertEqual(im.text, {'TXT': 'VALUE', 'ZIP': 'VALUE'})
|
||||||
|
|
||||||
def test_exif(self):
|
def test_exif(self):
|
||||||
|
im = Image.open("Tests/images/exif.png")
|
||||||
|
exif = im._getexif()
|
||||||
|
self.assertEqual(exif[274], 1)
|
||||||
|
|
||||||
|
def test_exif_save(self):
|
||||||
|
im = Image.open("Tests/images/exif.png")
|
||||||
|
|
||||||
|
test_file = self.tempfile("temp.png")
|
||||||
|
im.save(test_file)
|
||||||
|
|
||||||
|
reloaded = Image.open(test_file)
|
||||||
|
exif = reloaded._getexif()
|
||||||
|
self.assertEqual(exif[274], 1)
|
||||||
|
|
||||||
|
def test_exif_from_jpg(self):
|
||||||
im = Image.open("Tests/images/pil_sample_rgb.jpg")
|
im = Image.open("Tests/images/pil_sample_rgb.jpg")
|
||||||
|
|
||||||
test_file = self.tempfile("temp.png")
|
test_file = self.tempfile("temp.png")
|
||||||
|
|
|
@ -462,6 +462,10 @@ PNG
|
||||||
Pillow identifies, reads, and writes PNG files containing ``1``, ``L``, ``P``,
|
Pillow identifies, reads, and writes PNG files containing ``1``, ``L``, ``P``,
|
||||||
``RGB``, or ``RGBA`` data. Interlaced files are supported as of v1.1.7.
|
``RGB``, or ``RGBA`` data. Interlaced files are supported as of v1.1.7.
|
||||||
|
|
||||||
|
As of Pillow 6.0, EXIF data can be read from PNG images. However, unlike other
|
||||||
|
image formats, EXIF data is not guaranteed to have been read until
|
||||||
|
:py:meth:`~PIL.Image.Image.load` has been called.
|
||||||
|
|
||||||
The :py:meth:`~PIL.Image.Image.open` method sets the following
|
The :py:meth:`~PIL.Image.Image.open` method sets the following
|
||||||
:py:attr:`~PIL.Image.Image.info` properties, when appropriate:
|
:py:attr:`~PIL.Image.Image.info` properties, when appropriate:
|
||||||
|
|
||||||
|
@ -527,6 +531,11 @@ The :py:meth:`~PIL.Image.Image.save` method supports the following options:
|
||||||
**icc_profile**
|
**icc_profile**
|
||||||
The ICC Profile to include in the saved file.
|
The ICC Profile to include in the saved file.
|
||||||
|
|
||||||
|
**exif**
|
||||||
|
The exif data to include in the saved file.
|
||||||
|
|
||||||
|
.. versionadded:: 6.0.0
|
||||||
|
|
||||||
**bits (experimental)**
|
**bits (experimental)**
|
||||||
For ``P`` images, this option controls how many bits to store. If omitted,
|
For ``P`` images, this option controls how many bits to store. If omitted,
|
||||||
the PNG writer uses 8 bits (256 colors).
|
the PNG writer uses 8 bits (256 colors).
|
||||||
|
|
|
@ -112,6 +112,13 @@ Image.quantize
|
||||||
|
|
||||||
The `dither` option is now a customisable parameter (was previously hardcoded to `1`). This parameter takes the same values used in `Image.convert`
|
The `dither` option is now a customisable parameter (was previously hardcoded to `1`). This parameter takes the same values used in `Image.convert`
|
||||||
|
|
||||||
|
PNG EXIF Data
|
||||||
|
^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
EXIF data can now be read from and saved to PNG images. However, unlike other image
|
||||||
|
formats, EXIF data is not guaranteed to have been read until
|
||||||
|
:py:meth:`~PIL.Image.Image.load` has been called.
|
||||||
|
|
||||||
Other Changes
|
Other Changes
|
||||||
=============
|
=============
|
||||||
|
|
||||||
|
|
|
@ -689,6 +689,8 @@ class PngImageFile(ImageFile.ImageFile):
|
||||||
self.png = None
|
self.png = None
|
||||||
|
|
||||||
def _getexif(self):
|
def _getexif(self):
|
||||||
|
if "exif" not in self.info:
|
||||||
|
self.load()
|
||||||
from .JpegImagePlugin import _getexif
|
from .JpegImagePlugin import _getexif
|
||||||
return _getexif(self)
|
return _getexif(self)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user