reno/libs/thumbnail.lua

30 lines
1.0 KiB
Lua
Raw Normal View History

2022-07-12 21:26:11 +00:00
-- A small utility function to generate thumbnails for images
local spawn = require("awful.spawn")
local thumbnailer = {}
-- annoying shit but that's what happens
if _VERSION ~= "Lua 5.1" then
execute = function(comm)
return select(3,os.execute(comm))
end
else
execute = os.execute
end
thumbnailer.generate = function(path,thumb_path,height)
assert(type(path) == "string", "argumenr #1 (path) is not a string")
assert(type(thumb_path) == "string", "argument #2 (thumbnail path) is not a string")
assert(type(height) == "number","argument #3 (height) is not a number")
if execute("ls "..path) ~= 0 then
return false, "unable to access image directory"
end
if execute("ls "..thumb_path) == 0 then
return true
end
if execute("mkdir "..thumb_path) ~= 0 then
return false, "unable to create thumbnail directory"
end
spawn("mogrify -thumbnail x"..tostring(height).." -path '"..thumb_path.."' '"..path.."'/*.{jpg,png}")
return true
end
return thumbnailer