Skip to content

Commit 3f0e0ea

Browse files
committed
Initial gimp_stack.lua from wpferguson
Received from wpferguson 2019-11-24 via darktable-org#196 (comment)
1 parent 7c7118d commit 3f0e0ea

File tree

1 file changed

+140
-0
lines changed

1 file changed

+140
-0
lines changed

contrib/gimp_stack.lua

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
--[[
2+
3+
gimp_stack.lua - export multiple images and open as layers in gimp
4+
5+
Copyright (C) 2016 Bill Ferguson <[email protected]>.
6+
7+
Portions are lifted from hugin.lua and thus are
8+
9+
Copyright (c) 2014 Wolfgang Goetz
10+
Copyright (c) 2015 Christian Kanzian
11+
Copyright (c) 2015 Tobias Jakobs
12+
13+
14+
This program is free software: you can redistribute it and/or modify
15+
it under the terms of the GNU General Public License as published by
16+
the Free Software Foundation; either version 3 of the License, or
17+
(at your option) any later version.
18+
19+
This program is distributed in the hope that it will be useful,
20+
but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22+
GNU General Public License for more details.
23+
24+
You should have received a copy of the GNU General Public License
25+
along with this program. If not, see <http://www.gnu.org/licenses/>.
26+
]]
27+
--[[
28+
gimp_stack - export multiple images and open as layers with gimp for editing
29+
30+
This script provides another storage (export target) for darktable. Selected
31+
images are exported in the specified format to temporary storage. The images are
32+
combined into a single file. Gimp is launched and opens the merged file. A dialog
33+
prompts to import the image as layers. After editing, the image is imported back into
34+
the current collection, using the path of the first image selected, as stack.tif.
35+
The image is then imported into the database. The exported files that made up the
36+
stacked image are deleted from temporary storage to avoid cluttering up the system.
37+
38+
39+
ADDITIONAL SOFTWARE NEEDED FOR THIS SCRIPT
40+
* gimp - http://www.gimp.org
41+
* imagemagick - http://www.imagemagick.org
42+
43+
USAGE
44+
* require this script from your main lua file
45+
* select an images to stack and edit with gimp
46+
* in the export dialog select "Edit as layers with gimp" and select the format and bit depth for the
47+
exported image
48+
* Press "export"
49+
* Import the image as layers when gimp starts
50+
* Edit the image with gimp then save the changes with File->Overwrite....
51+
* Exit gimp
52+
* The edited image will be imported and grouped with the original collection
53+
54+
CAVEATS
55+
* Developed and tested on Ubuntu 14.04 LTS with darktable 2.0.3 and gimp 2.9.3 (development version with
56+
> 8 bit color)
57+
* There is no provision for dealing with the xcf files generated by gimp, since darktable doesn't deal with
58+
them. You may want to save the xcf file if you intend on doing further edits to the image or need to save
59+
the layers used. Where you save them is up to you.
60+
61+
BUGS, COMMENTS, SUGGESTIONS
62+
* Send to Bill Ferguson, [email protected]
63+
]]
64+
65+
local dt = require "darktable"
66+
local dtutils = require "contrib/dtutils"
67+
local gettext = dt.gettext
68+
69+
dt.configuration.check_version(...,{3,0,0})
70+
71+
-- Tell gettext where to find the .mo file translating messages for a particular domain
72+
gettext.bindtextdomain("gimp_stack",dt.configuration.config_dir.."/lua/")
73+
74+
-- Thanks to http://lua-users.org/wiki/SplitJoin for the split and split_path functions
75+
local function _(msgid)
76+
return gettext.dgettext("gimp_stack", msgid)
77+
end
78+
79+
local function show_status(storage, image, format, filename,
80+
number, total, high_quality, extra_data)
81+
dt.print(string.format(_("Exporting to gimp %i/%i"), number, total))
82+
end
83+
84+
local function gimp_stack_edit(storage, image_table, extra_data) --finalize
85+
if not dtutils.checkIfBinExists("gimp") then
86+
dt.print_error(_("gimp not found"))
87+
return
88+
end
89+
90+
if not dtutils.checkIfBinExists("convert") then
91+
dt.print_error(_("convert not found"))
92+
return
93+
end
94+
95+
-- list of exported images
96+
local img_list
97+
98+
-- reset and create image list
99+
img_list = ""
100+
101+
for _,exp_img in pairs(image_table) do
102+
img_list = img_list ..exp_img.. " "
103+
end
104+
dt.print_error(img_list)
105+
106+
local tmp_stack_image = dt.configuration.tmp_dir.."/stack.tif"
107+
108+
dt.print(_("Stacking images..."))
109+
110+
os.execute("convert "..img_list.." "..tmp_stack_image)
111+
os.execute("rm "..img_list)
112+
113+
dt.print(_("Launching gimp..."))
114+
115+
local gimpStartCommand
116+
gimpStartCommand = "gimp "..tmp_stack_image
117+
118+
dt.print_error(gimpStartCommand)
119+
120+
coroutine.yield("RUN_COMMAND", gimpStartCommand)
121+
122+
-- for each of the exported images
123+
-- find the matching original image
124+
-- then move the exported image into the directory with the original
125+
-- then import the image into the database which will group it with the original
126+
-- and then copy over any tags other than darktable tags
127+
128+
local collection_path = dt.gui.action_images[1].path
129+
local final_stack_image = collection_path.."/stack.tif"
130+
os.execute("mv "..tmp_stack_image.." "..final_stack_image)
131+
local myimage = dt.database.import(final_stack_image)
132+
133+
end
134+
135+
-- Register
136+
dt.register_storage("module_gimp_stack", _("Edit as layers with gimp"), show_status, gimp_stack_edit)
137+
138+
--
139+
140+

0 commit comments

Comments
 (0)