Fixed issue with exporting RAW images
This commit is contained in:
@@ -30,6 +30,7 @@ This script is only tested with Linux
|
|||||||
|
|
||||||
USAGE
|
USAGE
|
||||||
* require this script from your main Lua file
|
* 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
|
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)
|
local function create_kml_file(storage, image_table, extra_data)
|
||||||
|
|
||||||
if not checkIfBinExists("mkdir") then
|
if not checkIfBinExists("mkdir") then
|
||||||
@@ -186,7 +200,7 @@ local function create_kml_file(storage, image_table, extra_data)
|
|||||||
-- Creates dir if not exsists
|
-- Creates dir if not exsists
|
||||||
imageFoldername = "files/"
|
imageFoldername = "files/"
|
||||||
local mkdirCommand = "mkdir -p "..exportDirectory.."/"..imageFoldername
|
local mkdirCommand = "mkdir -p "..exportDirectory.."/"..imageFoldername
|
||||||
dt.control.execute( mkdirCommand)
|
coroutine.yield("RUN_COMMAND", mkdirCommand)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@@ -196,7 +210,7 @@ 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
|
(image.longitude ~= 0 and image.latitude ~= 90) -- Sometimes the north-pole but most likely just wrong data
|
||||||
) then
|
) then
|
||||||
local path, filename, filetype = string.match(exported_image, "(.-)([^\\/]-%.?([^%.\\/]*))$")
|
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
|
-- 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
|
-- In this example, '-size 120x120' gives a hint to the JPEG decoder that the image is going to be downscaled to
|
||||||
@@ -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.
|
-- 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"
|
local convertToThumbCommand = "convert -size 96x96 "..exported_image.." -resize 92x92 -mattecolor \"#FFFFFF\" -frame 2x2 +profile \"*\" "..exportDirectory.."/"..imageFoldername.."thumb_"..filename..".jpg"
|
||||||
dt.control.execute( convertToThumbCommand)
|
-- USE coroutine.yield. It does not block the UI
|
||||||
local concertCommand = "convert -size 438x438 "..exported_image.." -resize 438x438 +profile \"*\" "..exportDirectory.."/"..imageFoldername..filename..".jpg"
|
coroutine.yield("RUN_COMMAND", convertToThumbCommand)
|
||||||
|
|
||||||
dt.control.execute( concertCommand)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- delete the original image to not get into the kmz file
|
|
||||||
os.remove(exported_image)
|
|
||||||
|
|
||||||
local pattern = "[/]?([^/]+)$"
|
local pattern = "[/]?([^/]+)$"
|
||||||
filmName = string.match(image.film.path, pattern)
|
filmName = string.match(image.film.path, pattern)
|
||||||
|
|
||||||
-- Strip accents from the filename, because GoogleEarth can't open them
|
-- Strip accents from the filename, because GoogleEarth can't open them
|
||||||
-- https://github.com/darktable-org/lua-scripts/issues/54
|
-- https://github.com/darktable-org/lua-scripts/issues/54
|
||||||
filmName = string.stripAccents(filmName)
|
filmName = string.stripAccents(filmName)
|
||||||
end
|
end
|
||||||
|
|
||||||
exportKMLFilename = filmName..".kml"
|
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"
|
kml_file = kml_file.." <description>Exported from darktable</description>\n"
|
||||||
|
|
||||||
for image,exported_image in pairs(image_table) do
|
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
|
if ((image.longitude and image.latitude) and
|
||||||
(image.longitude ~= 0 and image.latitude ~= 90) -- Sometimes the north-pole but most likely just wrong data
|
(image.longitude ~= 0 and image.latitude ~= 90) -- Sometimes the north-pole but most likely just wrong data
|
||||||
) then
|
) then
|
||||||
kml_file = kml_file.." <Placemark>\n"
|
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
|
else
|
||||||
kml_file = kml_file.." <name>"..image.filename.."</name>\n"
|
image_title = image.filename
|
||||||
end
|
end
|
||||||
|
image_description = string.escapeXmlCharacters(image.description)
|
||||||
|
|
||||||
kml_file = kml_file.." <description>"..image.description.."</description>\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.." <Style>\n"
|
||||||
kml_file = kml_file.." <IconStyle>\n"
|
kml_file = kml_file.." <IconStyle>\n"
|
||||||
kml_file = kml_file.." <Icon>\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.." </Icon>\n"
|
||||||
kml_file = kml_file.." </IconStyle>\n"
|
kml_file = kml_file.." </IconStyle>\n"
|
||||||
kml_file = kml_file.." <BalloonStyle>\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.." <textColor>ff000000</textColor>\n"
|
||||||
kml_file = kml_file.." <displayMode>default</displayMode>\n"
|
kml_file = kml_file.." <displayMode>default</displayMode>\n"
|
||||||
kml_file = kml_file.." </BalloonStyle>\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
|
-- Compress the files to create a KMZ file
|
||||||
if ( dt.preferences.read("kml_export","CreateKMZ","bool") == true ) then
|
if ( dt.preferences.read("kml_export","CreateKMZ","bool") == true ) then
|
||||||
exportDirectory = dt.preferences.read("kml_export","ExportDirectory","string")
|
exportDirectory = dt.preferences.read("kml_export","ExportDirectory","string")
|
||||||
|
-- USE coroutine.yield. It does not block the UI
|
||||||
|
|
||||||
local createKMZCommand = "zip --test --move --junk-paths "
|
local createKMZCommand = "zip --test --move --junk-paths "
|
||||||
createKMZCommand = createKMZCommand .."\""..exportDirectory.."/"..exportKMZFilename.."\" " -- KMZ filename
|
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
|
if ((image.longitude and image.latitude) and
|
||||||
(image.longitude ~= 0 and image.latitude ~= 90) -- Sometimes the north-pole but most likely just wrong data
|
(image.longitude ~= 0 and image.latitude ~= 90) -- Sometimes the north-pole but most likely just wrong data
|
||||||
) then
|
) 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.."thumb_"..filename..".jpg\" " -- thumbnails
|
||||||
createKMZCommand = createKMZCommand .."\""..dt.configuration.tmp_dir.."/"..imageFoldername..filename..".jpg\" " -- images
|
createKMZCommand = createKMZCommand .."\""..exported_image.."\" " -- images
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
dt.control.execute( createKMZCommand)
|
coroutine.yield("RUN_COMMAND", createKMZCommand)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Open the file with the standard programm
|
-- Open the file with the standard programm
|
||||||
@@ -348,7 +362,7 @@ local function create_kml_file(storage, image_table, extra_data)
|
|||||||
else
|
else
|
||||||
kmlFileOpenCommand = "xdg-open "..exportDirectory.."/\""..exportKMLFilename.."\""
|
kmlFileOpenCommand = "xdg-open "..exportDirectory.."/\""..exportKMLFilename.."\""
|
||||||
end
|
end
|
||||||
dt.control.execute( kmlFileOpenCommand)
|
coroutine.yield("RUN_COMMAND", kmlFileOpenCommand)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user