mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-13 18:56:17 +03:00
commit
eb9464eb6c
|
@ -13,6 +13,7 @@ from .helper import (
|
|||
assert_not_all_same,
|
||||
hopper,
|
||||
is_win32,
|
||||
skip_unless_feature,
|
||||
)
|
||||
|
||||
|
||||
|
@ -625,6 +626,97 @@ class TestImage:
|
|||
|
||||
assert not fp.closed
|
||||
|
||||
def test_exif_jpeg(self, tmp_path):
|
||||
with Image.open("Tests/images/exif-72dpi-int.jpg") as im: # Little endian
|
||||
exif = im.getexif()
|
||||
assert 258 not in exif
|
||||
assert 40960 in exif
|
||||
assert exif[40963] == 450
|
||||
assert exif[11] == "gThumb 3.0.1"
|
||||
|
||||
out = str(tmp_path / "temp.jpg")
|
||||
exif[258] = 8
|
||||
del exif[40960]
|
||||
exif[40963] = 455
|
||||
exif[11] = "Pillow test"
|
||||
im.save(out, exif=exif)
|
||||
with Image.open(out) as reloaded:
|
||||
reloaded_exif = reloaded.getexif()
|
||||
assert reloaded_exif[258] == 8
|
||||
assert 40960 not in reloaded_exif
|
||||
assert reloaded_exif[40963] == 455
|
||||
assert reloaded_exif[11] == "Pillow test"
|
||||
|
||||
with Image.open("Tests/images/no-dpi-in-exif.jpg") as im: # Big endian
|
||||
exif = im.getexif()
|
||||
assert 258 not in exif
|
||||
assert 40962 in exif
|
||||
assert exif[40963] == 200
|
||||
assert exif[305] == "Adobe Photoshop CC 2017 (Macintosh)"
|
||||
|
||||
out = str(tmp_path / "temp.jpg")
|
||||
exif[258] = 8
|
||||
del exif[34665]
|
||||
exif[40963] = 455
|
||||
exif[305] = "Pillow test"
|
||||
im.save(out, exif=exif)
|
||||
with Image.open(out) as reloaded:
|
||||
reloaded_exif = reloaded.getexif()
|
||||
assert reloaded_exif[258] == 8
|
||||
assert 34665 not in reloaded_exif
|
||||
assert reloaded_exif[40963] == 455
|
||||
assert reloaded_exif[305] == "Pillow test"
|
||||
|
||||
@skip_unless_feature("webp")
|
||||
@skip_unless_feature("webp_anim")
|
||||
def test_exif_webp(self, tmp_path):
|
||||
with Image.open("Tests/images/hopper.webp") as im:
|
||||
exif = im.getexif()
|
||||
assert exif == {}
|
||||
|
||||
out = str(tmp_path / "temp.webp")
|
||||
exif[258] = 8
|
||||
exif[40963] = 455
|
||||
exif[305] = "Pillow test"
|
||||
|
||||
def check_exif():
|
||||
with Image.open(out) as reloaded:
|
||||
reloaded_exif = reloaded.getexif()
|
||||
assert reloaded_exif[258] == 8
|
||||
assert reloaded_exif[40963] == 455
|
||||
assert reloaded_exif[305] == "Pillow test"
|
||||
|
||||
im.save(out, exif=exif)
|
||||
check_exif()
|
||||
im.save(out, exif=exif, save_all=True)
|
||||
check_exif()
|
||||
|
||||
def test_exif_png(self, tmp_path):
|
||||
with Image.open("Tests/images/exif.png") as im:
|
||||
exif = im.getexif()
|
||||
assert exif == {274: 1}
|
||||
|
||||
out = str(tmp_path / "temp.png")
|
||||
exif[258] = 8
|
||||
del exif[274]
|
||||
exif[40963] = 455
|
||||
exif[305] = "Pillow test"
|
||||
im.save(out, exif=exif)
|
||||
|
||||
with Image.open(out) as reloaded:
|
||||
reloaded_exif = reloaded.getexif()
|
||||
assert reloaded_exif == {258: 8, 40963: 455, 305: "Pillow test"}
|
||||
|
||||
def test_exif_interop(self):
|
||||
with Image.open("Tests/images/flower.jpg") as im:
|
||||
exif = im.getexif()
|
||||
assert exif.get_ifd(0xA005) == {
|
||||
1: "R98",
|
||||
2: b"0100",
|
||||
4097: 2272,
|
||||
4098: 1704,
|
||||
}
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"test_module", [PIL, Image],
|
||||
)
|
||||
|
|
|
@ -243,94 +243,3 @@ class TestPyDecoder:
|
|||
im = MockImageFile(buf)
|
||||
assert im.format is None
|
||||
assert im.get_format_mimetype() is None
|
||||
|
||||
def test_exif_jpeg(self, tmp_path):
|
||||
with Image.open("Tests/images/exif-72dpi-int.jpg") as im: # Little endian
|
||||
exif = im.getexif()
|
||||
assert 258 not in exif
|
||||
assert 40960 in exif
|
||||
assert exif[40963] == 450
|
||||
assert exif[11] == "gThumb 3.0.1"
|
||||
|
||||
out = str(tmp_path / "temp.jpg")
|
||||
exif[258] = 8
|
||||
del exif[40960]
|
||||
exif[40963] = 455
|
||||
exif[11] = "Pillow test"
|
||||
im.save(out, exif=exif)
|
||||
with Image.open(out) as reloaded:
|
||||
reloaded_exif = reloaded.getexif()
|
||||
assert reloaded_exif[258] == 8
|
||||
assert 40960 not in reloaded_exif
|
||||
assert reloaded_exif[40963] == 455
|
||||
assert reloaded_exif[11] == "Pillow test"
|
||||
|
||||
with Image.open("Tests/images/no-dpi-in-exif.jpg") as im: # Big endian
|
||||
exif = im.getexif()
|
||||
assert 258 not in exif
|
||||
assert 40962 in exif
|
||||
assert exif[40963] == 200
|
||||
assert exif[305] == "Adobe Photoshop CC 2017 (Macintosh)"
|
||||
|
||||
out = str(tmp_path / "temp.jpg")
|
||||
exif[258] = 8
|
||||
del exif[34665]
|
||||
exif[40963] = 455
|
||||
exif[305] = "Pillow test"
|
||||
im.save(out, exif=exif)
|
||||
with Image.open(out) as reloaded:
|
||||
reloaded_exif = reloaded.getexif()
|
||||
assert reloaded_exif[258] == 8
|
||||
assert 34665 not in reloaded_exif
|
||||
assert reloaded_exif[40963] == 455
|
||||
assert reloaded_exif[305] == "Pillow test"
|
||||
|
||||
@skip_unless_feature("webp")
|
||||
@skip_unless_feature("webp_anim")
|
||||
def test_exif_webp(self, tmp_path):
|
||||
with Image.open("Tests/images/hopper.webp") as im:
|
||||
exif = im.getexif()
|
||||
assert exif == {}
|
||||
|
||||
out = str(tmp_path / "temp.webp")
|
||||
exif[258] = 8
|
||||
exif[40963] = 455
|
||||
exif[305] = "Pillow test"
|
||||
|
||||
def check_exif():
|
||||
with Image.open(out) as reloaded:
|
||||
reloaded_exif = reloaded.getexif()
|
||||
assert reloaded_exif[258] == 8
|
||||
assert reloaded_exif[40963] == 455
|
||||
assert reloaded_exif[305] == "Pillow test"
|
||||
|
||||
im.save(out, exif=exif)
|
||||
check_exif()
|
||||
im.save(out, exif=exif, save_all=True)
|
||||
check_exif()
|
||||
|
||||
def test_exif_png(self, tmp_path):
|
||||
with Image.open("Tests/images/exif.png") as im:
|
||||
exif = im.getexif()
|
||||
assert exif == {274: 1}
|
||||
|
||||
out = str(tmp_path / "temp.png")
|
||||
exif[258] = 8
|
||||
del exif[274]
|
||||
exif[40963] = 455
|
||||
exif[305] = "Pillow test"
|
||||
im.save(out, exif=exif)
|
||||
|
||||
with Image.open(out) as reloaded:
|
||||
reloaded_exif = reloaded.getexif()
|
||||
assert reloaded_exif == {258: 8, 40963: 455, 305: "Pillow test"}
|
||||
|
||||
def test_exif_interop(self):
|
||||
with Image.open("Tests/images/flower.jpg") as im:
|
||||
exif = im.getexif()
|
||||
assert exif.get_ifd(0xA005) == {
|
||||
1: "R98",
|
||||
2: b"0100",
|
||||
4097: 2272,
|
||||
4098: 1704,
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user