Check image format before reading EXIF data

master
Dan Howe 7 years ago
parent 0f7d9a05d2
commit 783590745e

@ -94,19 +94,16 @@ def export_kml_file(dirname, fnames, kml_name):
kml = simplekml.Kml()
for fname in fnames:
try:
print('Reading {}...'.format(fname))
with Image.open(os.path.join(dirname, fname)) as image:
exif_data = get_exif_data(image)
print('Reading {}...'.format(fname))
lat, lon = get_lat_lon(exif_data)
pnt = kml.newpoint(name=fname)
pnt.coords = [(lon, lat)]
# Add content to popup window
pnt.description = (
'<![CDATA[ <img src={} height="500px" />]]>'.format(
pnt.description = ('<![CDATA[ <img src={} height="500px" />]]>'.format(
os.path.join(dirname, fname)))
pnt.stylemap.normalstyle.iconstyle.scale = 1
pnt.stylemap.normalstyle.iconstyle.icon.href = (
@ -115,8 +112,6 @@ def export_kml_file(dirname, fnames, kml_name):
pnt.stylemap.highlightstyle.iconstyle.scale = 2
pnt.stylemap.highlightstyle.iconstyle.icon.href = os.path.join(
dirname, fname)
except OSError:
print('Skipping {} (not a valid image).'.format(fname))
kml.save(kml_name)
@ -128,8 +123,9 @@ def main():
args = parser.parse_args()
# Get files in image directory
ext = ['.jpg', '.jpeg', '.tif', '.tiff']
dirname = args.folder
fnames = os.listdir(dirname)
fnames = [f for f in os.listdir(dirname) if os.path.splitext(f)[-1] in ext]
# Create kml file
kml_name = dirname + '.kml'

Loading…
Cancel
Save