Use thumbnail previews to save memory in Google Earth

master
Dan Howe 7 years ago
parent 45ca2d5d1c
commit df4492bcb2

@ -87,7 +87,7 @@ def get_lat_lon(exif_data):
return lat, lon
def export_kml_file(dirname, fnames, kml_name):
def export_kml_file(dirname, fnames, dirname_thumbs, kml_name):
"""
Create the kml document
"""
@ -96,23 +96,32 @@ def export_kml_file(dirname, fnames, kml_name):
for fname in fnames:
print('Reading {}...'.format(fname))
with Image.open(os.path.join(dirname, fname)) as image:
# Get EXIF tags
exif_data = get_exif_data(image)
# Save thumbnail
image.thumbnail((128, 128))
image.save(os.path.join(dirname_thumbs, fname), 'jpeg')
lat, lon = get_lat_lon(exif_data)
pnt = kml.newpoint(name=fname)
pnt.coords = [(lon, lat)]
# Add content to popup window
# Add popup window with full-size image
pnt.description = (
'<![CDATA[ <img src="{}"" height="500px" />]]>'.format(
os.path.join(dirname, fname)))
# Show groups of photos as camera icon
pnt.stylemap.normalstyle.iconstyle.scale = 1
pnt.stylemap.normalstyle.iconstyle.icon.href = (
'http://maps.google.com/'
'mapfiles/kml/shapes/camera.png')
pnt.stylemap.highlightstyle.iconstyle.scale = 2
# Show placemark as image thumbnail
pnt.stylemap.highlightstyle.iconstyle.scale = 3
pnt.stylemap.highlightstyle.iconstyle.icon.href = os.path.join(
dirname, fname)
dirname_thumbs, fname)
kml.save(kml_name)
@ -131,9 +140,16 @@ def main():
if os.path.splitext(f)[-1].lower() in ext
]
# Create thumbnails folder
dirname_thumbs = dirname + '-thumbs'
try:
os.mkdir(dirname_thumbs)
except FileExistsError:
pass
# Create kml file
kml_name = dirname + '.kml'
export_kml_file(dirname, fnames, kml_name)
export_kml_file(dirname, fnames, dirname_thumbs, kml_name)
if __name__ == '__main__':

Loading…
Cancel
Save