1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU Affero General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU Affero General Public License for more details.
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23 from mediagoblin
.tools
.exif
import exif_fix_image_orientation
, \
24 extract_exif
, clean_exif
, get_gps_data
, get_useful
25 from .resources
import GOOD_JPG
, EMPTY_JPG
, BAD_JPG
, GPS_JPG
26 from mediagoblin
.tools
.testing
import _activate_testing
32 assert a
in b
, "%r not in %r" % (a
, b
)
35 def test_exif_extraction():
37 Test EXIF extraction from a good image
39 result
= extract_exif(GOOD_JPG
)
40 clean
= clean_exif(result
)
41 useful
= get_useful(clean
)
42 gps
= get_gps_data(result
)
44 # Do we have the result?
45 assert len(result
) == 56
47 # Do we have clean data?
48 assert len(clean
) == 53
53 # Do we have the "useful" tags?
57 'printable': u
'Flash did not fire',
62 'EXIF ExposureTime': {
78 'printable': 'NIKON D80',
81 'values': 'NIKON D80',
85 'printable': 'NIKON CORPORATION',
88 'values': 'NIKON CORPORATION',
90 'EXIF ExposureMode': {
92 'printable': 'Manual Exposure',
97 'EXIF ISOSpeedRatings': {
113 def test_exif_image_orientation():
115 Test image reorientation based on EXIF data
117 result
= extract_exif(GOOD_JPG
)
119 image
= exif_fix_image_orientation(
120 Image
.open(GOOD_JPG
),
123 # Are the dimensions correct?
124 assert image
.size
== (428, 640)
126 # If this pixel looks right, the rest of the image probably will too.
127 assert_in(image
.getdata()[10000],
128 ((41, 28, 11), (43, 27, 11))
132 def test_exif_no_exif():
134 Test an image without exif
136 result
= extract_exif(EMPTY_JPG
)
137 clean
= clean_exif(result
)
138 useful
= get_useful(clean
)
139 gps
= get_gps_data(result
)
147 def test_exif_bad_image():
149 Test EXIF extraction from a faithful, but bad image
151 result
= extract_exif(BAD_JPG
)
152 clean
= clean_exif(result
)
153 useful
= get_useful(clean
)
154 gps
= get_gps_data(result
)
162 def test_exif_gps_data():
164 Test extractiion of GPS data
166 result
= extract_exif(GPS_JPG
)
167 gps
= get_gps_data(result
)
170 'latitude': 59.336666666666666,
171 'direction': 25.674046740467404,
172 'altitude': 37.64365671641791,
173 'longitude': 18.016166666666667}