Skip to content
Open
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
18 changes: 13 additions & 5 deletions contrib/rename_images.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
--[[
rename - rename an image file or files

This shortcut resets the GPS information to that contained within
the image file. If no GPS info is in the image file, the GPS data
is cleared.

USAGE
* require this script from your luarc file or start it from script_manager
* select an image or images
Expand Down Expand Up @@ -96,6 +92,18 @@ local function stop_job(job)
job.valid = false
end

-- make sure filename ends with the image's original extension
local function ensure_extension(filename, image)
local original_extension = df.get_filetype(image.filename)
if original_extension ~= "" then
local suffix = "." .. original_extension
if string.lower(string.sub(filename, -string.len(suffix))) ~= string.lower(suffix) then
filename = filename .. suffix
end
end
return filename
end

local function install_module()
if not rename.module_installed then
dt.register_lib(
Expand Down Expand Up @@ -154,7 +162,7 @@ local function do_rename(images)
if string.len(path) == 0 then
path = image.path
end
local filename = df.get_filename(new_name)
local filename = ensure_extension(df.get_filename(new_name), image)
local filmname = image.path
if path ~= image.path then
if not df.check_if_file_exists(df.sanitize_filename(path)) then
Expand Down