Skip to content

Commit 7f09e55

Browse files
authored
Merge pull request #616 from wpferguson/fix_multi_os
examples/multi_os - replaced ufraw-batch with exiftool
2 parents f83ac13 + df78522 commit 7f09e55

File tree

1 file changed

+44
-9
lines changed

1 file changed

+44
-9
lines changed

examples/multi_os.lua

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929
by hovering over the image and pressing the key combination.
3030
3131
ADDITIONAL SOFTWARE NEEDED FOR THIS SCRIPT
32-
* ufraw-batch - https://ufraw.sourceforge.net
33-
MacOS - install with homebrew
32+
* exiftool - https://exiftool.org
3433
3534
USAGE
3635
* require this script from your main lua file
@@ -44,6 +43,7 @@
4443
* Send to Bill Ferguson, wpferguson@gmail.com
4544
4645
CHANGES
46+
20251205 - replaced ufraw-batch with exiftool
4747
]]
4848

4949
--[[
@@ -139,6 +139,36 @@ local function copy_image_attributes(from, to, ...)
139139
end
140140
end
141141

142+
local function check_file_size(img_name)
143+
local result = 0
144+
145+
if dt.configuration.running_os == "windows" then
146+
local path = df.get_path(img_name)
147+
local fname = df.get_filename(img_name)
148+
149+
local p = io.open("forfiles /P " .. path .. " /M " .. fname .. " /C \"cmd /c echo $fsize\"")
150+
151+
if p then
152+
for line in p:lines() do
153+
if line:length() > 5 then
154+
result = tonumber(line)
155+
end
156+
end
157+
p:close()
158+
end
159+
else
160+
local p = io.popen("ls -s " .. img_name)
161+
162+
if p then
163+
local line = p:read("*a")
164+
result = tonumber(du.split(line, " ")[1])
165+
p:close()
166+
end
167+
end
168+
169+
return result
170+
end
171+
142172
--[[
143173
The main function called from the button or the shortcut. It takes one or more raw files, passed
144174
in a table and extracts the embedded jpeg images
@@ -152,20 +182,25 @@ local function extract_embedded_jpeg(images)
152182
in the user's path. When it finds the executable, it returns the command to run it.
153183
]]
154184

155-
local ufraw_executable = df.check_if_bin_exists("ufraw-batch")
156-
if ufraw_executable then
185+
local exiftool_executable = df.check_if_bin_exists("exiftool")
186+
if exiftool_executable then
157187
for _, image in ipairs(images) do
158188
if image.is_raw then
159-
local img_file = du.join({image.path, image.filename}, "/")
189+
local img_file = tostring(image)
190+
local jpg_img_file = string.gsub(img_file, "%....$", ".jpg")
160191

161192
--[[
162193
dtsys.external_command() is operating system aware and formats the command as necessary.
163194
df.sanitize_filename() is used to quote the image filepath to protect from spaces. It is also
164195
operating system aware and uses the corresponding quotes.
165196
]]
166197

167-
if dtsys.external_command(ufraw_executable .. " --silent --embedded-image " .. df.sanitize_filename(img_file)) then
168-
local jpg_img_file = df.chop_filetype(img_file) .. ".embedded.jpg"
198+
if dtsys.external_command(exiftool_executable .. " -b -JpgFromRaw " .. df.sanitize_filename(img_file) .. " > " .. df.sanitize_filename(jpg_img_file)) then
199+
dt.print_log("created jpg from raw")
200+
if check_file_size(df.sanitize_filename(jpg_img_file)) == 0 then
201+
dt.print_log("using preview")
202+
dtsys.external_command(exiftool_executable .. " -b -PreviewImage " .. df.sanitize_filename(img_file) .. " > " .. df.sanitize_filename(jpg_img_file))
203+
end
169204
dt.print_log("jpg_img_file set to ", jpg_img_file) -- print a debugging message
170205
local myimage = dt.database.import(jpg_img_file)
171206
myimage:group_with(image.group_leader)
@@ -188,8 +223,8 @@ local function extract_embedded_jpeg(images)
188223
end
189224
end
190225
else
191-
dt.print_error("ufraw-batch not found. Exiting...") -- print debugging error message
192-
dt.print("ufraw-batch not found, exiting...") -- print the error to the screen
226+
dt.print_error("exiftool not found. Exiting...") -- print debugging error message
227+
dt.print("exiftool not found, exiting...") -- print the error to the screen
193228
end
194229
end
195230

0 commit comments

Comments
 (0)