From 679ce8b6ab79de9c9b66c95b8702da9c405e5dc8 Mon Sep 17 00:00:00 2001 From: Bill Ferguson Date: Wed, 6 Apr 2016 22:21:13 -0400 Subject: [PATCH 01/10] Created gimp.lua to export an image to gimp for editing, then return the result and group it with the original image --- contrib/gimp.lua | 179 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 179 insertions(+) create mode 100644 contrib/gimp.lua diff --git a/contrib/gimp.lua b/contrib/gimp.lua new file mode 100644 index 0000000..2b4720a --- /dev/null +++ b/contrib/gimp.lua @@ -0,0 +1,179 @@ +--[[ + + gimp.lua - export and edit with gimp + + Copyright (C) 2016 Bill Ferguson . + + Portions are lifted from hugin.lua and thus are + + Copyright (c) 2014 Wolfgang Goetz + Copyright (c) 2015 Christian Kanzian + Copyright (c) 2015 Tobias Jakobs + + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +]] +--[[ + gimp - export an image and open with gimp for editing + + This script provides another storage (export target) for darktable. Selected + images are exported in the specified format to temporary storage. Gimp is launched + and opens the files. After editing, the exported images are overwritten to save the + changes. When gimp exits, the exported files are moved into the current collection + and imported into the database. The imported files then show up grouped with the + originally selected images. + + ADDITIONAL SOFTWARE NEEDED FOR THIS SCRIPT + * gimp - http://www.gimp.org + + USAGE + * require this script from your main lua file + * select an image or images for editing with gimp + * in the export dialog select "Edit with gimp" and select the format and bit depth for the + exported image + * Press "export" + * Edit the image with gimp then save the changes with File->Overwrite.... + * Exit gimp + * The edited image will be imported and grouped with the original image + + CAVEATS + * Developed and tested on Ubuntu 14.04 LTS with darktable 2.0.3 and gimp 2.9.3 (development version with + > 8 bit color) + * There is no provision for dealing with the xcf files generated by gimp, since darktable doesn't deal with + them. You may want to save the xcf file if you intend on doing further edits to the image or need to save + the layers used. Where you save them is up to you. + + BUGS, COMMENTS, SUGGESTIONS + * Send to Bill Ferguson, wpferguson@gmail.com +]] + +local dt = require "darktable" +local gettext = dt.gettext + +dt.configuration.check_version(...,{3,0,0}) + +-- Tell gettext where to find the .mo file translating messages for a particular domain +gettext.bindtextdomain("gimp",dt.configuration.config_dir.."/lua/") + +-- Thanks to http://lua-users.org/wiki/SplitJoin for the split and split_path functions +local function split(str, pat) + local t = {} -- NOTE: use {n = 0} in Lua-5.0 + local fpat = "(.-)" .. pat + local last_end = 1 + local s, e, cap = str:find(fpat, 1) + while s do + if s ~= 1 or cap ~= "" then + table.insert(t,cap) + end + last_end = e+1 + s, e, cap = str:find(fpat, last_end) + end + if last_end <= #str then + cap = str:sub(last_end) + table.insert(t, cap) + end + return t +end + +local function split_path(str) + return split(str,'[\\/]+') +end + +local function get_filename(str) + parts = split_path(str) + return parts[#parts] +end + +local function basename(str) + return string.sub(str,1,-4) +end + +local function _(msgid) + return gettext.dgettext("gimp", msgid) +end + +local function checkIfBinExists(bin) + local handle = io.popen("which "..bin) + local result = handle:read() + local ret + handle:close() + if (result) then + dt.print_error("true checkIfBinExists: "..bin) + ret = true + else + dt.print_error(bin.." not found") + ret = false + end + return ret +end + +local function show_status(storage, image, format, filename, + number, total, high_quality, extra_data) + dt.print("Exporting to gimp "..tostring(number).."/"..tostring(total)) +end + +local function gimp_edit(storage, image_table, extra_data) --finalize + if not checkIfBinExists("gimp") then + dt.print_error(_("gimp not found")) + return + end + + -- list of exported images + local img_list + + -- reset and create image list + img_list = "" + + for _,v in pairs(image_table) do + img_list = img_list ..v.. " " + end + + dt.print(_("Launching gimp...")) + + local gimpStartCommand + gimpStartCommand = "gimp "..img_list + + dt.print_error(gimpStartCommand) + + coroutine.yield("RUN_COMMAND", gimpStartCommand) + + -- for each of the exported images + -- find the matching original image + -- then move the exported image into the directory with the original + -- then import the image into the database which will group it with the original + -- and then copy over any tags other than darktable tags + + for _,v in pairs(image_table) do + local fname = get_filename(v) + for _,w in pairs(dt.gui.action_images) do + if basename(fname) == basename(w.filename) then + os.execute("mv "..v.." "..w.path) + local myimage = dt.database.import(w.path.."/"..fname) + for _,x in pairs(dt.tags.get_tags(w)) do + if not (string.sub(x.name,1,9) == "darktable") then + dt.tags.attach(x,myimage) + end + end + end + end + end + +end + +-- Register +dt.register_storage("module_gimp", _("Edit with gimp"), show_status, gimp_edit) + +-- + + From 4556c9a055addbc5eb8e534e53aefcb73ccacbff Mon Sep 17 00:00:00 2001 From: Bill Ferguson Date: Thu, 7 Apr 2016 11:59:41 -0400 Subject: [PATCH 02/10] Incorporated comments from supertobi, marking string for translation on line 128 and expanding variable names for lines 157-165 --- contrib/gimp.lua | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/contrib/gimp.lua b/contrib/gimp.lua index 2b4720a..df1ead8 100644 --- a/contrib/gimp.lua +++ b/contrib/gimp.lua @@ -120,7 +120,7 @@ end local function show_status(storage, image, format, filename, number, total, high_quality, extra_data) - dt.print("Exporting to gimp "..tostring(number).."/"..tostring(total)) + dt.print(string.format(_("Exporting to gimp %i/%i", number, total))) end local function gimp_edit(storage, image_table, extra_data) --finalize @@ -135,8 +135,8 @@ local function gimp_edit(storage, image_table, extra_data) --finalize -- reset and create image list img_list = "" - for _,v in pairs(image_table) do - img_list = img_list ..v.. " " + for _,exp_img in pairs(image_table) do + img_list = img_list ..exp_img.. " " end dt.print(_("Launching gimp...")) @@ -154,15 +154,15 @@ local function gimp_edit(storage, image_table, extra_data) --finalize -- then import the image into the database which will group it with the original -- and then copy over any tags other than darktable tags - for _,v in pairs(image_table) do - local fname = get_filename(v) - for _,w in pairs(dt.gui.action_images) do - if basename(fname) == basename(w.filename) then - os.execute("mv "..v.." "..w.path) - local myimage = dt.database.import(w.path.."/"..fname) - for _,x in pairs(dt.tags.get_tags(w)) do - if not (string.sub(x.name,1,9) == "darktable") then - dt.tags.attach(x,myimage) + for _,exp_img in pairs(image_table) do + local fname = get_filename(exp_img) + for _,orig_img in pairs(dt.gui.action_images) do + if basename(fname) == basename(orig_img.filename) then + os.execute("mv "..exp_img.." "..orig_img.path) + local myimage = dt.database.import(orig_img.path.."/"..fname) + for _,tag in pairs(dt.tags.get_tags(orig_img)) do + if not (string.sub(tag.name,1,9) == "darktable") then + dt.tags.attach(tag,myimage) end end end From 8224913b0190e52b759f250a8a3d8a59f2d00950 Mon Sep 17 00:00:00 2001 From: Bill Ferguson Date: Sat, 9 Apr 2016 01:37:54 -0400 Subject: [PATCH 03/10] replaced string.format in show_status with the string and concatenation since string.format was having problems with the arguments. --- contrib/gimp.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/gimp.lua b/contrib/gimp.lua index df1ead8..e34f77f 100644 --- a/contrib/gimp.lua +++ b/contrib/gimp.lua @@ -120,7 +120,7 @@ end local function show_status(storage, image, format, filename, number, total, high_quality, extra_data) - dt.print(string.format(_("Exporting to gimp %i/%i", number, total))) + dt.print(_("Exporting to gimp "..tostring(number).."/"..tostring(total))) end local function gimp_edit(storage, image_table, extra_data) --finalize From 9693b017c427ee6df917773fba5c61a0b1e31cb2 Mon Sep 17 00:00:00 2001 From: Bill Ferguson Date: Sun, 10 Apr 2016 16:27:49 -0400 Subject: [PATCH 04/10] Changed back to string.format in show_status but coded it correctly this time. --- contrib/gimp.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/gimp.lua b/contrib/gimp.lua index e34f77f..b546e70 100644 --- a/contrib/gimp.lua +++ b/contrib/gimp.lua @@ -120,7 +120,7 @@ end local function show_status(storage, image, format, filename, number, total, high_quality, extra_data) - dt.print(_("Exporting to gimp "..tostring(number).."/"..tostring(total))) + dt.print(string.format(_("Export Image %i/%i"), number, total)) end local function gimp_edit(storage, image_table, extra_data) --finalize From 9dbd1d9bda1622ba0091dc2bd674100a03825a8d Mon Sep 17 00:00:00 2001 From: Bill Ferguson Date: Thu, 14 Apr 2016 16:34:37 -0400 Subject: [PATCH 05/10] Incorporated supertobi's comments. Changed os.execute to os.rename to handle spaces and special characters. Capitalized GIMP in all print strings. Added de_DE translation. --- contrib/de_DE/LC_MESSAGES/gimp.po | 39 +++++++ gimp.lua | 186 ++++++++++++++++++++++++++++++ 2 files changed, 225 insertions(+) create mode 100644 contrib/de_DE/LC_MESSAGES/gimp.po create mode 100644 gimp.lua diff --git a/contrib/de_DE/LC_MESSAGES/gimp.po b/contrib/de_DE/LC_MESSAGES/gimp.po new file mode 100644 index 0000000..b3b0447 --- /dev/null +++ b/contrib/de_DE/LC_MESSAGES/gimp.po @@ -0,0 +1,39 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: gimp\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2016-04-13 23:50-0400\n" +"PO-Revision-Date: 2016-04-14 00:11-0500\n" +"Last-Translator: Bill Ferguson \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 1.5.4\n" +"Language: de_DE\n" +"X-Poedit-SourceCharset: UTF-8\n" +"X-Poedit-KeywordsList: gettext;dgettext:2;dcgettext:2ngettext:1,2;" +"dngettext:2,3\n" +"X-Poedit-Basepath: .\n" + +#: gimp.lua:123 +#, lua-format +msgid "Export Image %i/%i" +msgstr "Exportiere Bild %i/%i" + +#: gimp.lua:129 +msgid "GIMP not found" +msgstr "GIMP nicht gefunden" + +#: gimp.lua:143 +msgid "Launching GIMP..." +msgstr "Starten von GIMP" + +#: gimp.lua:182 +msgid "Edit with GIMP" +msgstr "Bearbeiten mit Gimp" diff --git a/gimp.lua b/gimp.lua new file mode 100644 index 0000000..107a191 --- /dev/null +++ b/gimp.lua @@ -0,0 +1,186 @@ +--[[ + + gimp.lua - export and edit with GIMP + + Copyright (C) 2016 Bill Ferguson . + + Portions are lifted from hugin.lua and thus are + + Copyright (c) 2014 Wolfgang Goetz + Copyright (c) 2015 Christian Kanzian + Copyright (c) 2015 Tobias Jakobs + + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +]] +--[[ + gimp - export an image and open with GIMP for editing + + This script provides another storage (export target) for darktable. Selected + images are exported in the specified format to temporary storage. GIMP is launched + and opens the files. After editing, the exported images are overwritten to save the + changes. When GIMP exits, the exported files are moved into the current collection + and imported into the database. The imported files then show up grouped with the + originally selected images. + + ADDITIONAL SOFTWARE NEEDED FOR THIS SCRIPT + * GIMP - http://www.gimp.org + + USAGE + * require this script from your main lua file + * select an image or images for editing with GIMP + * in the export dialog select "Edit with GIMP" and select the format and bit depth for the + exported image + * Press "export" + * Edit the image with GIMP then save the changes with File->Overwrite.... + * Exit GIMP + * The edited image will be imported and grouped with the original image + + CAVEATS + * Developed and tested on Ubuntu 14.04 LTS with darktable 2.0.3 and GIMP 2.9.3 (development version with + > 8 bit color) + * There is no provision for dealing with the xcf files generated by GIMP, since darktable doesn't deal with + them. You may want to save the xcf file if you intend on doing further edits to the image or need to save + the layers used. Where you save them is up to you. + + BUGS, COMMENTS, SUGGESTIONS + * Send to Bill Ferguson, wpferguson@gmail.com +]] + +local dt = require "darktable" +local gettext = dt.gettext + +dt.configuration.check_version(...,{3,0,0}) + +-- Tell gettext where to find the .mo file translating messages for a particular domain +gettext.bindtextdomain("gimp",dt.configuration.config_dir.."/lua/") + +-- Thanks to http://lua-users.org/wiki/SplitJoin for the split and split_path functions +local function split(str, pat) + local t = {} -- NOTE: use {n = 0} in Lua-5.0 + local fpat = "(.-)" .. pat + local last_end = 1 + local s, e, cap = str:find(fpat, 1) + while s do + if s ~= 1 or cap ~= "" then + table.insert(t,cap) + end + last_end = e+1 + s, e, cap = str:find(fpat, last_end) + end + if last_end <= #str then + cap = str:sub(last_end) + table.insert(t, cap) + end + return t +end + +local function split_path(str) + return split(str,'[\\/]+') +end + +local function get_filename(str) + parts = split_path(str) + return parts[#parts] +end + +local function basename(str) + return string.sub(str,1,-4) +end + +local function _(msgid) + return gettext.dgettext("gimp", msgid) +end + +local function checkIfBinExists(bin) + local handle = io.popen("which "..bin) + local result = handle:read() + local ret + handle:close() + if (result) then + dt.print_error("true checkIfBinExists: "..bin) + ret = true + else + dt.print_error(bin.." not found") + ret = false + end + return ret +end + +local function show_status(storage, image, format, filename, + number, total, high_quality, extra_data) + dt.print(string.format(_("Export Image %i/%i"), number, total)) +-- dt.print(_(string.format("Exporting to gimp %i/%i", number, total))) +end + +local function gimp_edit(storage, image_table, extra_data) --finalize + if not checkIfBinExists("gimp") then + dt.print_error(_("GIMP not found")) + return + end + + -- list of exported images + local img_list + + -- reset and create image list + img_list = "" + + for _,exp_img in pairs(image_table) do + img_list = img_list ..exp_img.. " " + end + + dt.print(_("Launching GIMP...")) + + local gimpStartCommand + gimpStartCommand = "gimp "..img_list + + dt.print_error(gimpStartCommand) + + coroutine.yield("RUN_COMMAND", gimpStartCommand) + + -- for each of the exported images + -- find the matching original image + -- then move the exported image into the directory with the original + -- then import the image into the database which will group it with the original + -- and then copy over any tags other than darktable tags + + for _,exp_img in pairs(image_table) do + local fname = get_filename(exp_img) + dt.print_error(fname) + for _,orig_img in pairs(dt.gui.action_images) do + if basename(fname) == basename(orig_img.filename) then + dt.print_error("moving file...") + local myimage_name = orig_img.path .. "/" .. fname + dt.print_error(myimage_name) + result = os.rename(exp_img, myimage_name) + dt.print_error("importing file") + local myimage = dt.database.import(myimage_name) + for _,tag in pairs(dt.tags.get_tags(orig_img)) do + if not (string.sub(tag.name,1,9) == "darktable") then + dt.print_error("attaching tag") + dt.tags.attach(tag,myimage) + end + end + end + end + end + +end + +-- Register +dt.register_storage("module_gimp", _("Edit with GIMP"), show_status, gimp_edit) + +-- + + From 9c40a22c5012a47727dfb76ecae68dce0f3638ff Mon Sep 17 00:00:00 2001 From: Bill Ferguson Date: Thu, 14 Apr 2016 22:21:32 -0400 Subject: [PATCH 06/10] Removed gimp.lua from the top level --- gimp.lua | 186 ------------------------------------------------------- 1 file changed, 186 deletions(-) delete mode 100644 gimp.lua diff --git a/gimp.lua b/gimp.lua deleted file mode 100644 index 107a191..0000000 --- a/gimp.lua +++ /dev/null @@ -1,186 +0,0 @@ ---[[ - - gimp.lua - export and edit with GIMP - - Copyright (C) 2016 Bill Ferguson . - - Portions are lifted from hugin.lua and thus are - - Copyright (c) 2014 Wolfgang Goetz - Copyright (c) 2015 Christian Kanzian - Copyright (c) 2015 Tobias Jakobs - - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -]] ---[[ - gimp - export an image and open with GIMP for editing - - This script provides another storage (export target) for darktable. Selected - images are exported in the specified format to temporary storage. GIMP is launched - and opens the files. After editing, the exported images are overwritten to save the - changes. When GIMP exits, the exported files are moved into the current collection - and imported into the database. The imported files then show up grouped with the - originally selected images. - - ADDITIONAL SOFTWARE NEEDED FOR THIS SCRIPT - * GIMP - http://www.gimp.org - - USAGE - * require this script from your main lua file - * select an image or images for editing with GIMP - * in the export dialog select "Edit with GIMP" and select the format and bit depth for the - exported image - * Press "export" - * Edit the image with GIMP then save the changes with File->Overwrite.... - * Exit GIMP - * The edited image will be imported and grouped with the original image - - CAVEATS - * Developed and tested on Ubuntu 14.04 LTS with darktable 2.0.3 and GIMP 2.9.3 (development version with - > 8 bit color) - * There is no provision for dealing with the xcf files generated by GIMP, since darktable doesn't deal with - them. You may want to save the xcf file if you intend on doing further edits to the image or need to save - the layers used. Where you save them is up to you. - - BUGS, COMMENTS, SUGGESTIONS - * Send to Bill Ferguson, wpferguson@gmail.com -]] - -local dt = require "darktable" -local gettext = dt.gettext - -dt.configuration.check_version(...,{3,0,0}) - --- Tell gettext where to find the .mo file translating messages for a particular domain -gettext.bindtextdomain("gimp",dt.configuration.config_dir.."/lua/") - --- Thanks to http://lua-users.org/wiki/SplitJoin for the split and split_path functions -local function split(str, pat) - local t = {} -- NOTE: use {n = 0} in Lua-5.0 - local fpat = "(.-)" .. pat - local last_end = 1 - local s, e, cap = str:find(fpat, 1) - while s do - if s ~= 1 or cap ~= "" then - table.insert(t,cap) - end - last_end = e+1 - s, e, cap = str:find(fpat, last_end) - end - if last_end <= #str then - cap = str:sub(last_end) - table.insert(t, cap) - end - return t -end - -local function split_path(str) - return split(str,'[\\/]+') -end - -local function get_filename(str) - parts = split_path(str) - return parts[#parts] -end - -local function basename(str) - return string.sub(str,1,-4) -end - -local function _(msgid) - return gettext.dgettext("gimp", msgid) -end - -local function checkIfBinExists(bin) - local handle = io.popen("which "..bin) - local result = handle:read() - local ret - handle:close() - if (result) then - dt.print_error("true checkIfBinExists: "..bin) - ret = true - else - dt.print_error(bin.." not found") - ret = false - end - return ret -end - -local function show_status(storage, image, format, filename, - number, total, high_quality, extra_data) - dt.print(string.format(_("Export Image %i/%i"), number, total)) --- dt.print(_(string.format("Exporting to gimp %i/%i", number, total))) -end - -local function gimp_edit(storage, image_table, extra_data) --finalize - if not checkIfBinExists("gimp") then - dt.print_error(_("GIMP not found")) - return - end - - -- list of exported images - local img_list - - -- reset and create image list - img_list = "" - - for _,exp_img in pairs(image_table) do - img_list = img_list ..exp_img.. " " - end - - dt.print(_("Launching GIMP...")) - - local gimpStartCommand - gimpStartCommand = "gimp "..img_list - - dt.print_error(gimpStartCommand) - - coroutine.yield("RUN_COMMAND", gimpStartCommand) - - -- for each of the exported images - -- find the matching original image - -- then move the exported image into the directory with the original - -- then import the image into the database which will group it with the original - -- and then copy over any tags other than darktable tags - - for _,exp_img in pairs(image_table) do - local fname = get_filename(exp_img) - dt.print_error(fname) - for _,orig_img in pairs(dt.gui.action_images) do - if basename(fname) == basename(orig_img.filename) then - dt.print_error("moving file...") - local myimage_name = orig_img.path .. "/" .. fname - dt.print_error(myimage_name) - result = os.rename(exp_img, myimage_name) - dt.print_error("importing file") - local myimage = dt.database.import(myimage_name) - for _,tag in pairs(dt.tags.get_tags(orig_img)) do - if not (string.sub(tag.name,1,9) == "darktable") then - dt.print_error("attaching tag") - dt.tags.attach(tag,myimage) - end - end - end - end - end - -end - --- Register -dt.register_storage("module_gimp", _("Edit with GIMP"), show_status, gimp_edit) - --- - - From 6e5dbc0b83584679d8005cb3fed74a0f08281b65 Mon Sep 17 00:00:00 2001 From: Bill Ferguson Date: Fri, 15 Apr 2016 00:38:00 -0400 Subject: [PATCH 07/10] Incorporated supertobi's suggestions. Replaced file and path splitting code with a regular expression (thanks Tobias Jakobs) to ensure filenames were handled correctly. Used the image data in the image table pairs instead of darktable.gui.action_images to ensure there were no mismatches as well as clean up the code nicely. Updated gimp.po to reflect the line number changes due to code refactoring. --- contrib/de_DE/LC_MESSAGES/gimp.po | 8 +-- contrib/gimp.lua | 95 ++++++++++++------------------- 2 files changed, 39 insertions(+), 64 deletions(-) diff --git a/contrib/de_DE/LC_MESSAGES/gimp.po b/contrib/de_DE/LC_MESSAGES/gimp.po index b3b0447..3df09d1 100644 --- a/contrib/de_DE/LC_MESSAGES/gimp.po +++ b/contrib/de_DE/LC_MESSAGES/gimp.po @@ -21,19 +21,19 @@ msgstr "" "dngettext:2,3\n" "X-Poedit-Basepath: .\n" -#: gimp.lua:123 +#: gimp.lua:96 #, lua-format msgid "Export Image %i/%i" msgstr "Exportiere Bild %i/%i" -#: gimp.lua:129 +#: gimp.lua:101 msgid "GIMP not found" msgstr "GIMP nicht gefunden" -#: gimp.lua:143 +#: gimp.lua:115 msgid "Launching GIMP..." msgstr "Starten von GIMP" -#: gimp.lua:182 +#: gimp.lua:150 msgid "Edit with GIMP" msgstr "Bearbeiten mit Gimp" diff --git a/contrib/gimp.lua b/contrib/gimp.lua index b546e70..24be479 100644 --- a/contrib/gimp.lua +++ b/contrib/gimp.lua @@ -1,6 +1,6 @@ --[[ - gimp.lua - export and edit with gimp + gimp.lua - export and edit with GIMP Copyright (C) 2016 Bill Ferguson . @@ -25,32 +25,32 @@ along with this program. If not, see . ]] --[[ - gimp - export an image and open with gimp for editing + gimp - export an image and open with GIMP for editing This script provides another storage (export target) for darktable. Selected - images are exported in the specified format to temporary storage. Gimp is launched + images are exported in the specified format to temporary storage. GIMP is launched and opens the files. After editing, the exported images are overwritten to save the - changes. When gimp exits, the exported files are moved into the current collection + changes. When GIMP exits, the exported files are moved into the current collection and imported into the database. The imported files then show up grouped with the originally selected images. ADDITIONAL SOFTWARE NEEDED FOR THIS SCRIPT - * gimp - http://www.gimp.org + * GIMP - http://www.gimp.org USAGE * require this script from your main lua file - * select an image or images for editing with gimp - * in the export dialog select "Edit with gimp" and select the format and bit depth for the + * select an image or images for editing with GIMP + * in the export dialog select "Edit with GIMP" and select the format and bit depth for the exported image * Press "export" - * Edit the image with gimp then save the changes with File->Overwrite.... - * Exit gimp + * Edit the image with GIMP then save the changes with File->Overwrite.... + * Exit GIMP * The edited image will be imported and grouped with the original image CAVEATS - * Developed and tested on Ubuntu 14.04 LTS with darktable 2.0.3 and gimp 2.9.3 (development version with + * Developed and tested on Ubuntu 14.04 LTS with darktable 2.0.3 and GIMP 2.9.3 (development version with > 8 bit color) - * There is no provision for dealing with the xcf files generated by gimp, since darktable doesn't deal with + * There is no provision for dealing with the xcf files generated by GIMP, since darktable doesn't deal with them. You may want to save the xcf file if you intend on doing further edits to the image or need to save the layers used. Where you save them is up to you. @@ -66,37 +66,10 @@ dt.configuration.check_version(...,{3,0,0}) -- Tell gettext where to find the .mo file translating messages for a particular domain gettext.bindtextdomain("gimp",dt.configuration.config_dir.."/lua/") --- Thanks to http://lua-users.org/wiki/SplitJoin for the split and split_path functions -local function split(str, pat) - local t = {} -- NOTE: use {n = 0} in Lua-5.0 - local fpat = "(.-)" .. pat - local last_end = 1 - local s, e, cap = str:find(fpat, 1) - while s do - if s ~= 1 or cap ~= "" then - table.insert(t,cap) - end - last_end = e+1 - s, e, cap = str:find(fpat, last_end) - end - if last_end <= #str then - cap = str:sub(last_end) - table.insert(t, cap) - end - return t -end - -local function split_path(str) - return split(str,'[\\/]+') -end - local function get_filename(str) - parts = split_path(str) - return parts[#parts] -end - -local function basename(str) - return string.sub(str,1,-4) + -- Thanks to Tobias Jakobs for the awesome regular expression + local path, filename, filetype = string.match(str, "(.-)([^\\/]-%.?([^%.\\/]*))$") + return filename end local function _(msgid) @@ -125,7 +98,7 @@ end local function gimp_edit(storage, image_table, extra_data) --finalize if not checkIfBinExists("gimp") then - dt.print_error(_("gimp not found")) + dt.print_error(_("GIMP not found")) return end @@ -139,7 +112,7 @@ local function gimp_edit(storage, image_table, extra_data) --finalize img_list = img_list ..exp_img.. " " end - dt.print(_("Launching gimp...")) + dt.print(_("Launching GIMP...")) local gimpStartCommand gimpStartCommand = "gimp "..img_list @@ -148,23 +121,25 @@ local function gimp_edit(storage, image_table, extra_data) --finalize coroutine.yield("RUN_COMMAND", gimpStartCommand) - -- for each of the exported images - -- find the matching original image - -- then move the exported image into the directory with the original - -- then import the image into the database which will group it with the original - -- and then copy over any tags other than darktable tags + -- for each of the image, exported image pairs + -- move the exported image into the directory with the original + -- then import the image into the database which will group it with the original + -- and then copy over any tags other than darktable tags - for _,exp_img in pairs(image_table) do - local fname = get_filename(exp_img) - for _,orig_img in pairs(dt.gui.action_images) do - if basename(fname) == basename(orig_img.filename) then - os.execute("mv "..exp_img.." "..orig_img.path) - local myimage = dt.database.import(orig_img.path.."/"..fname) - for _,tag in pairs(dt.tags.get_tags(orig_img)) do - if not (string.sub(tag.name,1,9) == "darktable") then - dt.tags.attach(tag,myimage) - end - end + for image,exported_image in pairs(image_table) do + + local myimage_name = image.path .. "/" .. get_filename(exported_image) + + dt.print_error("moving " .. exported_image .. " to " .. myimage_name) + result = os.rename(exported_image, myimage_name) + + dt.print_error("importing file") + local myimage = dt.database.import(myimage_name) + + for _,tag in pairs(dt.tags.get_tags(image)) do + if not (string.sub(tag.name,1,9) == "darktable") then + dt.print_error("attaching tag") + dt.tags.attach(tag,myimage) end end end @@ -172,7 +147,7 @@ local function gimp_edit(storage, image_table, extra_data) --finalize end -- Register -dt.register_storage("module_gimp", _("Edit with gimp"), show_status, gimp_edit) +dt.register_storage("module_gimp", _("Edit with GIMP"), show_status, gimp_edit) -- From 623b506691bdb69d2e2686ce81d1ac403efc20ca Mon Sep 17 00:00:00 2001 From: Bill Ferguson Date: Fri, 15 Apr 2016 23:58:33 -0400 Subject: [PATCH 08/10] Added check to see if the export would overwrite an existing file. If it would, the filename was incremented with _XX where XX was an increment starting at 01 and ending at 99. gimp.po line numbers adjusted to reflect the changes in code. --- contrib/de_DE/LC_MESSAGES/gimp.po | 8 +-- contrib/gimp.lua | 99 ++++++++++++++++++++++++++++++- 2 files changed, 100 insertions(+), 7 deletions(-) diff --git a/contrib/de_DE/LC_MESSAGES/gimp.po b/contrib/de_DE/LC_MESSAGES/gimp.po index 3df09d1..4621455 100644 --- a/contrib/de_DE/LC_MESSAGES/gimp.po +++ b/contrib/de_DE/LC_MESSAGES/gimp.po @@ -21,19 +21,19 @@ msgstr "" "dngettext:2,3\n" "X-Poedit-Basepath: .\n" -#: gimp.lua:96 +#: gimp.lua:179 #, lua-format msgid "Export Image %i/%i" msgstr "Exportiere Bild %i/%i" -#: gimp.lua:101 +#: gimp.lua:184 msgid "GIMP not found" msgstr "GIMP nicht gefunden" -#: gimp.lua:115 +#: gimp.lua:198 msgid "Launching GIMP..." msgstr "Starten von GIMP" -#: gimp.lua:150 +#: gimp.lua:243 msgid "Edit with GIMP" msgstr "Bearbeiten mit Gimp" diff --git a/contrib/gimp.lua b/contrib/gimp.lua index 24be479..6a825a0 100644 --- a/contrib/gimp.lua +++ b/contrib/gimp.lua @@ -66,10 +66,31 @@ dt.configuration.check_version(...,{3,0,0}) -- Tell gettext where to find the .mo file translating messages for a particular domain gettext.bindtextdomain("gimp",dt.configuration.config_dir.."/lua/") +local function split_filepath(str) + local result = {} + -- Thank you Tobias Jakobs for the awesome regular expression, which I tweaked a little + result["path"], result["filename"], result["basename"], result["filetype"] = string.match(str, "(.-)(([^\\/]-)%.?([^%.\\/]*))$") + return result +end + +local function get_path(str) + local parts = split_filepath(str) + return parts["path"] +end + local function get_filename(str) - -- Thanks to Tobias Jakobs for the awesome regular expression - local path, filename, filetype = string.match(str, "(.-)([^\\/]-%.?([^%.\\/]*))$") - return filename + local parts = split_filepath(str) + return parts["filename"] +end + +local function get_basename(str) + local parts = split_filepath(str) + return parts["basename"] +end + +local function get_filetype(str) + local parts = split_filepath(str) + return parts["filetype"] end local function _(msgid) @@ -91,6 +112,68 @@ local function checkIfBinExists(bin) return ret end +local function checkIfFileExists(filepath) + local handle = io.popen("ls "..filepath) + local result = handle:read() + local ret + handle:close() + if (result) then + dt.print_error("true checkIfFileExists: "..filepath) + ret = true + else + dt.print_error(filepath.." not found") + ret = false + end + return ret +end + +local function filename_increment(filepath) + + -- break up the filepath into parts + local path = get_path(filepath) + local basename = get_basename(filepath) + local filetype = get_filetype(filepath) + + -- check to see if we've incremented before + local increment = string.match(basename, "_(%d-)$") + + if increment then + -- we do 2 digit increments so make sure we didn't grab part of the filename + if string.len(increment) > 2 then + -- we got the filename so set the increment to 01 + increment = "01" + else + increment = string.format("%02d", tonumber(increment) + 1) + basename = string.gsub(basename, "_(%d-)$", "") + end + else + increment = "01" + end + local incremented_filepath = path .. basename .. "_" .. increment .. "." .. filetype + + dt.print_error("original file was " .. filepath) + dt.print_error("incremented file is " .. incremented_filepath) + + return incremented_filepath +end + +local function groupIfNotMember(img, new_img) + local image_table = img:get_group_members() + local is_member = false + for _,image in ipairs(image_table) do + dt.print_error(image.filename .. " is a member") + if image.filename == new_img.filename then + is_member = true + dt.print_error("Already in group") + end + end + if not is_member then + dt.print_error("group leader is "..img.group_leader.filename) + new_img:group_with(img.group_leader) + dt.print_error("Added to group") + end +end + local function show_status(storage, image, format, filename, number, total, high_quality, extra_data) dt.print(string.format(_("Export Image %i/%i"), number, total)) @@ -130,12 +213,22 @@ local function gimp_edit(storage, image_table, extra_data) --finalize local myimage_name = image.path .. "/" .. get_filename(exported_image) + while checkIfFileExists(myimage_name) do + myimage_name = filename_increment(myimage_name) + -- limit to 99 more exports of the original export + if string.match(get_basename(myimage_name), "_(d-)$") == "99" then + break + end + end + dt.print_error("moving " .. exported_image .. " to " .. myimage_name) result = os.rename(exported_image, myimage_name) dt.print_error("importing file") local myimage = dt.database.import(myimage_name) + groupIfNotMember(image, myimage) + for _,tag in pairs(dt.tags.get_tags(image)) do if not (string.sub(tag.name,1,9) == "darktable") then dt.print_error("attaching tag") From 3dcb08cca3f7c920e478a7e70d4a21391b67439c Mon Sep 17 00:00:00 2001 From: Bill Ferguson Date: Sat, 16 Apr 2016 21:10:58 -0400 Subject: [PATCH 09/10] Replaced checkIfFileExists with supertobi's fix and capitalized GIMP in gimp.po where I missed it. --- contrib/de_DE/LC_MESSAGES/gimp.po | 2 +- contrib/gimp.lua | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/contrib/de_DE/LC_MESSAGES/gimp.po b/contrib/de_DE/LC_MESSAGES/gimp.po index 4621455..5c90119 100644 --- a/contrib/de_DE/LC_MESSAGES/gimp.po +++ b/contrib/de_DE/LC_MESSAGES/gimp.po @@ -36,4 +36,4 @@ msgstr "Starten von GIMP" #: gimp.lua:243 msgid "Edit with GIMP" -msgstr "Bearbeiten mit Gimp" +msgstr "Bearbeiten mit GIMP" diff --git a/contrib/gimp.lua b/contrib/gimp.lua index 6a825a0..b66f60f 100644 --- a/contrib/gimp.lua +++ b/contrib/gimp.lua @@ -112,15 +112,15 @@ local function checkIfBinExists(bin) return ret end -local function checkIfFileExists(filepath) - local handle = io.popen("ls "..filepath) - local result = handle:read() +-- Thanks Tobias Jakobs for the idea and the correction +function checkIfFileExists(filepath) + local file = io.open(filepath,"r") local ret - handle:close() - if (result) then + if file ~= nil then + io.close(file) dt.print_error("true checkIfFileExists: "..filepath) ret = true - else + else dt.print_error(filepath.." not found") ret = false end From 457731700c7bbaf19bb90a50ad5903dee4a00a84 Mon Sep 17 00:00:00 2001 From: Bill Ferguson Date: Sat, 16 Apr 2016 21:44:24 -0400 Subject: [PATCH 10/10] gimp doesn't like filenames with spaces in them, so added sanitize_filename to escape them. Updated gimp.po to reflect the changed line numbers. --- contrib/de_DE/LC_MESSAGES/gimp.po | 8 ++++---- contrib/gimp.lua | 11 +++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/contrib/de_DE/LC_MESSAGES/gimp.po b/contrib/de_DE/LC_MESSAGES/gimp.po index 5c90119..8b6dcbf 100644 --- a/contrib/de_DE/LC_MESSAGES/gimp.po +++ b/contrib/de_DE/LC_MESSAGES/gimp.po @@ -21,19 +21,19 @@ msgstr "" "dngettext:2,3\n" "X-Poedit-Basepath: .\n" -#: gimp.lua:179 +#: gimp.lua:189 #, lua-format msgid "Export Image %i/%i" msgstr "Exportiere Bild %i/%i" -#: gimp.lua:184 +#: gimp.lua:194 msgid "GIMP not found" msgstr "GIMP nicht gefunden" -#: gimp.lua:198 +#: gimp.lua:209 msgid "Launching GIMP..." msgstr "Starten von GIMP" -#: gimp.lua:243 +#: gimp.lua:254 msgid "Edit with GIMP" msgstr "Bearbeiten mit GIMP" diff --git a/contrib/gimp.lua b/contrib/gimp.lua index b66f60f..896fec3 100644 --- a/contrib/gimp.lua +++ b/contrib/gimp.lua @@ -174,6 +174,16 @@ local function groupIfNotMember(img, new_img) end end +local function sanitize_filename(filepath) + local path = get_path(filepath) + local basename = get_basename(filepath) + local filetype = get_filetype(filepath) + + local sanitized = string.gsub(basename, " ", "\\ ") + + return path .. sanitized .. "." .. filetype +end + local function show_status(storage, image, format, filename, number, total, high_quality, extra_data) dt.print(string.format(_("Export Image %i/%i"), number, total)) @@ -192,6 +202,7 @@ local function gimp_edit(storage, image_table, extra_data) --finalize img_list = "" for _,exp_img in pairs(image_table) do + exp_img = sanitize_filename(exp_img) img_list = img_list ..exp_img.. " " end