diff --git a/contrib/kml_export.lua b/contrib/kml_export.lua
index 7960287..1589a4a 100644
--- a/contrib/kml_export.lua
+++ b/contrib/kml_export.lua
@@ -30,6 +30,7 @@ This script is only tested with Linux
USAGE
* require this script from your main Lua file
+* when choosing file format, pick JPEG or PNG as Google Earth doesn't support other formats
]]
@@ -155,6 +156,19 @@ function string.stripAccents( str )
end
+-- Escape XML characters
+-- https://stackoverflow.com/questions/1091945/what-characters-do-i-need-to-escape-in-xml-documents
+function string.escapeXmlCharacters( str )
+
+ str = string.gsub(str,"&", "&")
+ str = string.gsub(str,"\"", """)
+ str = string.gsub(str,"'", "'")
+ str = string.gsub(str,"<", "<")
+ str = string.gsub(str,">", ">")
+
+ return str
+end
+
local function create_kml_file(storage, image_table, extra_data)
if not checkIfBinExists("mkdir") then
@@ -186,7 +200,7 @@ local function create_kml_file(storage, image_table, extra_data)
-- Creates dir if not exsists
imageFoldername = "files/"
local mkdirCommand = "mkdir -p "..exportDirectory.."/"..imageFoldername
- dt.control.execute( mkdirCommand)
+ coroutine.yield("RUN_COMMAND", mkdirCommand)
end
@@ -196,8 +210,8 @@ local function create_kml_file(storage, image_table, extra_data)
(image.longitude ~= 0 and image.latitude ~= 90) -- Sometimes the north-pole but most likely just wrong data
) then
local path, filename, filetype = string.match(exported_image, "(.-)([^\\/]-%.?([^%.\\/]*))$")
- filename = string.upper(string.gsub(filename,"%.", "_"))
-
+ filename = string.upper(string.gsub(filename,"%.%w*", ""))
+
-- convert -size 92x92 filename.jpg -resize 92x92 +profile "*" thumbnail.jpg
-- In this example, '-size 120x120' gives a hint to the JPEG decoder that the image is going to be downscaled to
-- 120x120, allowing it to run faster by avoiding returning full-resolution images to GraphicsMagick for the
@@ -206,21 +220,16 @@ local function create_kml_file(storage, image_table, extra_data)
-- profiles that might be present in the input and aren't needed in the thumbnail.
local convertToThumbCommand = "convert -size 96x96 "..exported_image.." -resize 92x92 -mattecolor \"#FFFFFF\" -frame 2x2 +profile \"*\" "..exportDirectory.."/"..imageFoldername.."thumb_"..filename..".jpg"
- dt.control.execute( convertToThumbCommand)
- local concertCommand = "convert -size 438x438 "..exported_image.." -resize 438x438 +profile \"*\" "..exportDirectory.."/"..imageFoldername..filename..".jpg"
-
- dt.control.execute( concertCommand)
+ -- USE coroutine.yield. It does not block the UI
+ coroutine.yield("RUN_COMMAND", convertToThumbCommand)
end
- -- delete the original image to not get into the kmz file
- os.remove(exported_image)
-
local pattern = "[/]?([^/]+)$"
filmName = string.match(image.film.path, pattern)
-
- -- Strip accents from the filename, because GoogleEarth can't open them
- -- https://github.com/darktable-org/lua-scripts/issues/54
- filmName = string.stripAccents(filmName)
+
+ -- Strip accents from the filename, because GoogleEarth can't open them
+ -- https://github.com/darktable-org/lua-scripts/issues/54
+ filmName = string.stripAccents(filmName)
end
exportKMLFilename = filmName..".kml"
@@ -236,20 +245,24 @@ local function create_kml_file(storage, image_table, extra_data)
kml_file = kml_file.." Exported from darktable\n"
for image,exported_image in pairs(image_table) do
- filename = string.upper(string.gsub(image.filename,"%.", "_"))
+ filename = string.upper(string.gsub(image.filename,"%.%w*", ""))
+ extension = string.match(exported_image,"%.%w*$")
if ((image.longitude and image.latitude) and
(image.longitude ~= 0 and image.latitude ~= 90) -- Sometimes the north-pole but most likely just wrong data
) then
kml_file = kml_file.." \n"
- if (image.title and image.title ~= "") then
- kml_file = kml_file.." "..image.title.."\n"
+
+ local image_title, image_description
+ if (image.title and image.title ~= "") then
+ image_title = string.escapeXmlCharacters(image.title)
else
- kml_file = kml_file.." "..image.filename.."\n"
+ image_title = image.filename
end
-
- kml_file = kml_file.." "..image.description.."\n"
-
+ image_description = string.escapeXmlCharacters(image.description)
+
+ kml_file = kml_file.." "..image_title.."\n"
+ kml_file = kml_file.." "..image_description.."\n"
kml_file = kml_file.."