Add photo module.

debian-sid
Tom Payne 15 years ago
parent 89ae650c2c
commit df03e46178

@ -22,6 +22,7 @@ import sys
import igc2kmz
import igc2kmz.igc
import igc2kmz.photo
def add_flight(option, opt, value, parser):
@ -33,7 +34,7 @@ def add_flight_option(option, opt, value, parser):
def add_flight_photo(option, opt, value, parser):
parser.values.flights[-1].photos.append(value)
parser.values.flights[-1].photos.append(igc2kmz.photo.Photo(value))
def main(argv):

@ -0,0 +1,41 @@
# igc2kmz/__init__.py igc2kmz photo module
# Copyright (C) 2008 Tom Payne
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import datetime
import re
import urllib2
import urlparse
import exif
EXIF_DATETIME_RE = re.compile(r'(\d+):(\d+):(\d+)\s+(\d+):(\d+):(\d+)')
class Photo(object):
def __init__(self, url):
if urlparse.urlparse(url).scheme:
self.url = url
else:
self.url = 'file://' + url
file = urllib2.urlopen(self.url)
if file.info().typeheader != 'image/jpeg':
raise RuntimeError, '%s: not an image/jpeg' % self.url
self.jpeg = exif.JPEG(file)
m = DATETIME_RE.match(self.jpeg.exif.get('DateTimeOriginal') or self.jpeg.exif.get('DateTime') or '')
self.dt = datetime.datetime(*map(int, m.groups())) if m else None
Loading…
Cancel
Save