forked from python-pillow/Pillow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_file_webp_metadata.py
112 lines (73 loc) · 2.94 KB
/
test_file_webp_metadata.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
from helper import unittest, PillowTestCase
from PIL import Image
class TestFileWebpMetadata(PillowTestCase):
def setUp(self):
try:
from PIL import _webp
except ImportError:
self.skipTest('WebP support not installed')
return
if not _webp.HAVE_WEBPMUX:
self.skipTest('WebPMux support not installed')
def test_read_exif_metadata(self):
file_path = "Tests/images/flower.webp"
image = Image.open(file_path)
self.assertEqual(image.format, "WEBP")
exif_data = image.info.get("exif", None)
self.assertTrue(exif_data)
exif = image._getexif()
# camera make
self.assertEqual(exif[271], "Canon")
jpeg_image = Image.open('Tests/images/flower.jpg')
expected_exif = jpeg_image.info['exif']
self.assertEqual(exif_data, expected_exif)
def test_write_exif_metadata(self):
from io import BytesIO
file_path = "Tests/images/flower.jpg"
image = Image.open(file_path)
expected_exif = image.info['exif']
test_buffer = BytesIO()
image.save(test_buffer, "webp", exif=expected_exif)
test_buffer.seek(0)
webp_image = Image.open(test_buffer)
webp_exif = webp_image.info.get('exif', None)
self.assertTrue(webp_exif)
if webp_exif:
self.assertEqual(
webp_exif, expected_exif, "WebP EXIF didn't match")
def test_read_icc_profile(self):
file_path = "Tests/images/flower2.webp"
image = Image.open(file_path)
self.assertEqual(image.format, "WEBP")
self.assertTrue(image.info.get("icc_profile", None))
icc = image.info['icc_profile']
jpeg_image = Image.open('Tests/images/flower2.jpg')
expected_icc = jpeg_image.info['icc_profile']
self.assertEqual(icc, expected_icc)
def test_write_icc_metadata(self):
from io import BytesIO
file_path = "Tests/images/flower2.jpg"
image = Image.open(file_path)
expected_icc_profile = image.info['icc_profile']
test_buffer = BytesIO()
image.save(test_buffer, "webp", icc_profile=expected_icc_profile)
test_buffer.seek(0)
webp_image = Image.open(test_buffer)
webp_icc_profile = webp_image.info.get('icc_profile', None)
self.assertTrue(webp_icc_profile)
if webp_icc_profile:
self.assertEqual(
webp_icc_profile, expected_icc_profile,
"Webp ICC didn't match")
def test_read_no_exif(self):
from io import BytesIO
file_path = "Tests/images/flower.jpg"
image = Image.open(file_path)
self.assertIn('exif', image.info)
test_buffer = BytesIO()
image.save(test_buffer, "webp")
test_buffer.seek(0)
webp_image = Image.open(test_buffer)
self.assertFalse(webp_image._getexif())
if __name__ == '__main__':
unittest.main()