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
29 assert a
in b
, "%r not in %r" % (a
, b
)
32 def test_exif_extraction():
34 Test EXIF extraction from a good image
36 result
= extract_exif(GOOD_JPG
)
37 clean
= clean_exif(result
)
38 useful
= get_useful(clean
)
39 gps
= get_gps_data(result
)
41 # Do we have the result?
42 assert len(result
) == 56
44 # Do we have clean data?
45 assert len(clean
) == 53
50 # Do we have the "useful" tags?
54 'printable': u
'Flash did not fire',
59 'EXIF ExposureTime': {
75 'printable': 'NIKON D80',
78 'values': 'NIKON D80',
82 'printable': 'NIKON CORPORATION',
85 'values': 'NIKON CORPORATION',
87 'EXIF ExposureMode': {
89 'printable': 'Manual Exposure',
94 'EXIF ISOSpeedRatings': {
110 def test_exif_image_orientation():
112 Test image reorientation based on EXIF data
114 result
= extract_exif(GOOD_JPG
)
116 image
= exif_fix_image_orientation(
117 Image
.open(GOOD_JPG
),
120 # Are the dimensions correct?
121 assert image
.size
== (428, 640)
123 # If this pixel looks right, the rest of the image probably will too.
124 assert_in(image
.getdata()[10000],
125 ((41, 28, 11), (43, 27, 11))
129 def test_exif_no_exif():
131 Test an image without exif
133 result
= extract_exif(EMPTY_JPG
)
134 clean
= clean_exif(result
)
135 useful
= get_useful(clean
)
136 gps
= get_gps_data(result
)
144 def test_exif_bad_image():
146 Test EXIF extraction from a faithful, but bad image
148 result
= extract_exif(BAD_JPG
)
149 clean
= clean_exif(result
)
150 useful
= get_useful(clean
)
151 gps
= get_gps_data(result
)
159 def test_exif_gps_data():
161 Test extractiion of GPS data
163 result
= extract_exif(GPS_JPG
)
164 gps
= get_gps_data(result
)
167 'latitude': 59.336666666666666,
168 'direction': 25.674046740467404,
169 'altitude': 37.64365671641791,
170 'longitude': 18.016166666666667}