-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompress_images.lua
More file actions
executable file
·29 lines (26 loc) · 1.02 KB
/
Copy pathcompress_images.lua
File metadata and controls
executable file
·29 lines (26 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env luajit
package.path = (arg[0]:match("@?(.*/)") or arg[0]:match("@?(.*\\)")) .. "lib" .. package.config:sub(1, 1) .. "?.lua;" .. package.path
local utility = require "utility"
utility.required_program("magick")
local image_extensions = { "png", "jpg", "jpeg", "gif", }
os.execute("mkdir compressed-images")
utility.ls(".", function(file_name)
local process_file = false
local _, bare_file_name, file_extension = utility.split_path_components(file_name)
if file_extension then
file_extension = file_extension:lower()
for _, extension in ipairs(image_extensions) do
if file_extension == extension then
process_file = true
break
end
end
end
if process_file then
local command = "magick " .. file_name:enquote()
if arg and arg[1] and arg[1] == "--trim" then
command = command .. " -fuzz 5% -trim -shave 3x3"
end
os.execute(command .. " -quality 75 " .. ("compressed-images/" .. bare_file_name:sub(1, -(#file_extension + 2)) .. ".jpg"):enquote())
end
end)