Fixed issue with exporting RAW images
This commit is contained in:
@@ -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.." <description>Exported from darktable</description>\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.." <Placemark>\n"
|
||||
if (image.title and image.title ~= "") then
|
||||
kml_file = kml_file.." <name>"..image.title.."</name>\n"
|
||||
|
||||
local image_title, image_description
|
||||
if (image.title and image.title ~= "") then
|
||||
image_title = string.escapeXmlCharacters(image.title)
|
||||
else
|
||||
kml_file = kml_file.." <name>"..image.filename.."</name>\n"
|
||||
image_title = image.filename
|
||||
end
|
||||
|
||||
kml_file = kml_file.." <description>"..image.description.."</description>\n"
|
||||
|
||||
image_description = string.escapeXmlCharacters(image.description)
|
||||
|
||||
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"
|
||||
@@ -257,7 +270,7 @@ local function create_kml_file(storage, image_table, extra_data)
|
||||
kml_file = kml_file.." </Icon>\n"
|
||||
kml_file = kml_file.." </IconStyle>\n"
|
||||
kml_file = kml_file.." <BalloonStyle>\n"
|
||||
kml_file = kml_file.." <text><![CDATA[<img src=\""..imageFoldername..filename..".jpg\"><br/>]]></text>\n"
|
||||
kml_file = kml_file.." <text><![CDATA[<p><b>"..image_title.."</b></p><img src=\""..imageFoldername..filename..extension.."\"><p>"..image_description.."</p>]]></text>\n"
|
||||
kml_file = kml_file.." <textColor>ff000000</textColor>\n"
|
||||
kml_file = kml_file.." <displayMode>default</displayMode>\n"
|
||||
kml_file = kml_file.." </BalloonStyle>\n"
|
||||
@@ -320,6 +333,7 @@ local function create_kml_file(storage, image_table, extra_data)
|
||||
-- Compress the files to create a KMZ file
|
||||
if ( dt.preferences.read("kml_export","CreateKMZ","bool") == true ) then
|
||||
exportDirectory = dt.preferences.read("kml_export","ExportDirectory","string")
|
||||
-- USE coroutine.yield. It does not block the UI
|
||||
|
||||
local createKMZCommand = "zip --test --move --junk-paths "
|
||||
createKMZCommand = createKMZCommand .."\""..exportDirectory.."/"..exportKMZFilename.."\" " -- KMZ filename
|
||||
@@ -329,14 +343,14 @@ local function create_kml_file(storage, image_table, extra_data)
|
||||
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,"%.", "_"))
|
||||
local filename = string.upper(string.gsub(image.filename,"%.%w*", ""))
|
||||
|
||||
createKMZCommand = createKMZCommand .."\""..dt.configuration.tmp_dir.."/"..imageFoldername.."thumb_"..filename..".jpg\" " -- thumbnails
|
||||
createKMZCommand = createKMZCommand .."\""..dt.configuration.tmp_dir.."/"..imageFoldername..filename..".jpg\" " -- images
|
||||
createKMZCommand = createKMZCommand .."\""..exported_image.."\" " -- images
|
||||
end
|
||||
end
|
||||
|
||||
dt.control.execute( createKMZCommand)
|
||||
coroutine.yield("RUN_COMMAND", createKMZCommand)
|
||||
end
|
||||
|
||||
-- Open the file with the standard programm
|
||||
@@ -348,7 +362,7 @@ local function create_kml_file(storage, image_table, extra_data)
|
||||
else
|
||||
kmlFileOpenCommand = "xdg-open "..exportDirectory.."/\""..exportKMLFilename.."\""
|
||||
end
|
||||
dt.control.execute( kmlFileOpenCommand)
|
||||
coroutine.yield("RUN_COMMAND", kmlFileOpenCommand)
|
||||
end
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user