Remove trailing whitespaces.
This commit is contained in:
@@ -35,13 +35,13 @@ USAGE
|
||||
* when choosing file format, pick JPEG or PNG as Google Earth doesn't support other formats
|
||||
|
||||
]]
|
||||
|
||||
|
||||
local dt = require "darktable"
|
||||
require "official/yield"
|
||||
|
||||
local gettext = dt.gettext
|
||||
dt.configuration.check_version(...,{3,0,0},{4,0,0})
|
||||
|
||||
|
||||
-- Tell gettext where to find the .mo file translating messages for a particular domain
|
||||
gettext.bindtextdomain("kml_export",dt.configuration.config_dir.."/lua/locale/")
|
||||
|
||||
@@ -56,7 +56,7 @@ local function spairs(_table, order) -- Code copied from http://stackoverflow.co
|
||||
for _key in pairs(_table) do keys[#keys + 1] = _key end
|
||||
|
||||
-- if order function given, sort by it by passing the table and keys a, b,
|
||||
-- otherwise just sort the keys
|
||||
-- otherwise just sort the keys
|
||||
if order then
|
||||
table.sort(keys, function(a,b) return order(_table, a, b) end)
|
||||
else
|
||||
@@ -89,7 +89,7 @@ local function checkIfBinExists(bin)
|
||||
ret = true
|
||||
return ret
|
||||
end
|
||||
|
||||
|
||||
-- Strip accents from a string
|
||||
-- Copied from https://forums.coronalabs.com/topic/43048-remove-special-characters-from-string/
|
||||
function string.stripAccents( str )
|
||||
@@ -145,7 +145,7 @@ function string.stripAccents( str )
|
||||
tableAccents["Û"] = "U"
|
||||
tableAccents["Ü"] = "U"
|
||||
tableAccents["Ý"] = "Y"
|
||||
|
||||
|
||||
local normalizedString = ""
|
||||
|
||||
for strChar in string.gmatch(str, "([%z\1-\127\194-\244][\128-\191]*)") do
|
||||
@@ -155,9 +155,9 @@ function string.stripAccents( str )
|
||||
normalizedString = normalizedString..strChar
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
return normalizedString
|
||||
|
||||
|
||||
end
|
||||
|
||||
-- Escape XML characters
|
||||
@@ -205,22 +205,22 @@ 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)
|
||||
dt.control.execute(mkdirCommand)
|
||||
end
|
||||
|
||||
|
||||
-- Create the thumbnails
|
||||
for image,exported_image in pairs(image_table) do
|
||||
if ((image.longitude and image.latitude) and
|
||||
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
|
||||
local path, filename, filetype = string.match(exported_image, "(.-)([^\\/]-%.?([^%.\\/]*))$")
|
||||
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
|
||||
-- subsequent resizing operation. The '-resize 120x120' specifies the desired dimensions of the output image. It
|
||||
-- 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
|
||||
-- subsequent resizing operation. The '-resize 120x120' specifies the desired dimensions of the output image. It
|
||||
-- will be scaled so its largest dimension is 120 pixels. The '+profile "*"' removes any ICM, EXIF, IPTC, or other
|
||||
-- profiles that might be present in the input and aren't needed in the thumbnail.
|
||||
|
||||
@@ -233,7 +233,7 @@ local function create_kml_file(storage, image_table, extra_data)
|
||||
|
||||
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)
|
||||
@@ -248,20 +248,20 @@ local function create_kml_file(storage, image_table, extra_data)
|
||||
kml_file = kml_file.."<Document>\n"
|
||||
|
||||
--image_table = dt.gui.selection();
|
||||
kml_file = kml_file.."<name>"..filmName.."</name>\n"
|
||||
kml_file = kml_file.."<name>"..filmName.."</name>\n"
|
||||
kml_file = kml_file.." <description>Exported from darktable</description>\n"
|
||||
|
||||
|
||||
for image,exported_image in pairs(image_table) do
|
||||
-- Extract filename, e.g DSC9784.ARW -> DSC9784
|
||||
filename = string.upper(string.gsub(image.filename,"%.%w*", ""))
|
||||
-- Extract extension from exported image (user can choose JPG or PNG), e.g DSC9784.JPG -> .JPG
|
||||
extension = string.match(exported_image,"%.%w*$")
|
||||
|
||||
if ((image.longitude and image.latitude) and
|
||||
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.." <Placemark>\n"
|
||||
|
||||
|
||||
local image_title, image_description
|
||||
if (image.title and image.title ~= "") then
|
||||
image_title = string.escapeXmlCharacters(image.title)
|
||||
@@ -271,12 +271,12 @@ local function create_kml_file(storage, image_table, extra_data)
|
||||
-- Characters should not be escaped in CDATA, but we are using HTML fragment, so we must escape them
|
||||
image_description = string.escapeXmlCharacters(image.description)
|
||||
|
||||
kml_file = kml_file.." <name>"..image_title.."</name>\n"
|
||||
kml_file = kml_file.." <name>"..image_title.."</name>\n"
|
||||
kml_file = kml_file.." <description>"..image_description.."</description>\n"
|
||||
kml_file = kml_file.." <Style>\n"
|
||||
kml_file = kml_file.." <IconStyle>\n"
|
||||
kml_file = kml_file.." <Icon>\n"
|
||||
kml_file = kml_file.." <href>"..imageFoldername.."thumb_"..filename..".jpg</href>\n"
|
||||
kml_file = kml_file.." <href>"..imageFoldername.."thumb_"..filename..".jpg</href>\n"
|
||||
kml_file = kml_file.." </Icon>\n"
|
||||
kml_file = kml_file.." </IconStyle>\n"
|
||||
kml_file = kml_file.." <BalloonStyle>\n"
|
||||
@@ -293,29 +293,29 @@ local function create_kml_file(storage, image_table, extra_data)
|
||||
kml_file = kml_file.." <when>"..string.gsub(image.exif_datetime_taken," ", "T").."Z".."</when>\n"
|
||||
kml_file = kml_file.." </TimeStamp>\n"
|
||||
kml_file = kml_file.." </Point>\n"
|
||||
|
||||
|
||||
kml_file = kml_file.." </Placemark>\n"
|
||||
end
|
||||
end
|
||||
|
||||
-- Connects all images with an path
|
||||
if ( dt.preferences.read("kml_export","CreatePath","bool") == true ) then
|
||||
kml_file = kml_file.." <Placemark>\n"
|
||||
kml_file = kml_file.." <Placemark>\n"
|
||||
kml_file = kml_file.." <name>Path</name>\n" -- ToDo: I think a better name would be nice
|
||||
--kml_file = kml_file.." <description></description>\n"
|
||||
|
||||
kml_file = kml_file.." <Style>\n"
|
||||
kml_file = kml_file.." <LineStyle>\n"
|
||||
kml_file = kml_file.." <Style>\n"
|
||||
kml_file = kml_file.." <LineStyle>\n"
|
||||
kml_file = kml_file.." <color>ff0000ff</color>\n"
|
||||
kml_file = kml_file.." <width>5</width>\n"
|
||||
kml_file = kml_file.." </LineStyle>\n"
|
||||
kml_file = kml_file.." </LineStyle>\n"
|
||||
kml_file = kml_file.." </Style>\n"
|
||||
|
||||
kml_file = kml_file.." <LineString>\n"
|
||||
kml_file = kml_file.." <coordinates>\n"
|
||||
|
||||
|
||||
for image,exported_image in spairs(image_table, function(t,a,b) return t[b] < t[a] end) do
|
||||
if ((image.longitude and image.latitude) and
|
||||
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
|
||||
local altitude = 0;
|
||||
@@ -349,7 +349,7 @@ local function create_kml_file(storage, image_table, extra_data)
|
||||
createKMZCommand = createKMZCommand .."\""..dt.configuration.tmp_dir.."/"..exportKMLFilename.."\" " -- KML file
|
||||
|
||||
for image,exported_image in pairs(image_table) do
|
||||
if ((image.longitude and image.latitude) and
|
||||
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
|
||||
local filename = string.upper(string.gsub(image.filename,"%.%w*", ""))
|
||||
@@ -362,7 +362,7 @@ local function create_kml_file(storage, image_table, extra_data)
|
||||
dt.control.execute(createKMZCommand)
|
||||
end
|
||||
|
||||
-- Open the file with the standard programm
|
||||
-- Open the file with the standard programm
|
||||
if ( dt.preferences.read("kml_export","OpenKmlFile","bool") == true ) then
|
||||
local kmlFileOpenCommand
|
||||
|
||||
@@ -371,7 +371,7 @@ local function create_kml_file(storage, image_table, extra_data)
|
||||
else
|
||||
kmlFileOpenCommand = "xdg-open "..exportDirectory.."/\""..exportKMLFilename.."\""
|
||||
end
|
||||
dt.control.execute(kmlFileOpenCommand)
|
||||
dt.control.execute(kmlFileOpenCommand)
|
||||
end
|
||||
|
||||
|
||||
@@ -406,7 +406,7 @@ dt.preferences.register("kml_export",
|
||||
"bool",
|
||||
_("KML export: Create KMZ file"),
|
||||
_("Compress all imeges to one KMZ file"),
|
||||
true )
|
||||
true )
|
||||
|
||||
-- Register
|
||||
dt.register_storage("kml_export", _("KML/KMZ Export"), nil, create_kml_file)
|
||||
|
||||
Reference in New Issue
Block a user