Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions contrib/de_DE/LC_MESSAGES/gimp.po
Original file line number Diff line number Diff line change
@@ -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 <EMAIL@ADDRESS>, 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 <wpferguson@gmail.com>\n"
"Language-Team: LANGUAGE <LL@li.org>\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:189
#, lua-format
msgid "Export Image %i/%i"
msgstr "Exportiere Bild %i/%i"

#: gimp.lua:194
msgid "GIMP not found"
msgstr "GIMP nicht gefunden"

#: gimp.lua:209
msgid "Launching GIMP..."
msgstr "Starten von GIMP"

#: gimp.lua:254
msgid "Edit with GIMP"
msgstr "Bearbeiten mit GIMP"
258 changes: 258 additions & 0 deletions contrib/gimp.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@
--[[

gimp.lua - export and edit with GIMP

Copyright (C) 2016 Bill Ferguson <wpferguson@gmail.com>.

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 <http://www.gnu.org/licenses/>.
]]
--[[
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/")

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)
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)
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

-- Thanks Tobias Jakobs for the idea and the correction
function checkIfFileExists(filepath)
local file = io.open(filepath,"r")
local ret
if file ~= nil then
io.close(file)
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 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))
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
exp_img = sanitize_filename(exp_img)
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 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 image,exported_image in pairs(image_table) do

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing that I thought about and haven't tested is: What happens if you import e.g. a jpeg in dt and then edit it with gimp as jpeg. Will you then overwrite the original file? If yes, you could do something like renaming the in gimp changed from FILENAME.jpg to FILENAME_gimp.jpg or FILENAME_1.jpg.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way it stands now, if you exported a raw to gimp as a .jpg, then exported the resulting .jpg to gimp, the .jpg would get overwritten when gimp exits. I could do the xxxx.jpg, then xxxx_01.jpg. The only question is if I export _01.jpg does it become _02.jpg or _01_01.jpg?

I also developed a shortcut for the occasion when you did want to overwrite the file, i.e. I exported and edited, but forgot to clone out one more thing so I'll just reopen it and fix it. While running that I discovered an unfortunate darktable "feature" (bug). If I've not opened the image in darkroom, then dropping the cache causes it to regenerate the thumbnail and it shows correctly. If I open the image in darkroom, it does not reflect the changes, so it seems that darkroom also maintains a cache. When you return to lighttable, the thumbnail gets regenerated again and shows the image without any changes, so it appears to regenerate from the darkroom cache. If you open it with gimp again and make more changes then save it, the thumbnail cache gets dropped, but it regenerates the image from the darkroom cache and not the file. The only way to get things synced up is to restart darktable.


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")
dt.tags.attach(tag,myimage)
end
end
end

end

-- Register
dt.register_storage("module_gimp", _("Edit with GIMP"), show_status, gimp_edit)

--