|
|
@ -1,17 +1,26 @@ |
|
|
|
-- 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 os.execute("ls "..path) ~= 0 then |
|
|
|
require("naughty").notify({text = tostring(path).." "..tostring(thumb_path.." ")..tostring(height)}) |
|
|
|
if execute("ls "..path) ~= 0 then |
|
|
|
return false, "unable to access image directory" |
|
|
|
end |
|
|
|
if os.execute("ls "..thumb_path) == 0 then |
|
|
|
if execute("ls "..thumb_path) == 0 then |
|
|
|
return true |
|
|
|
end |
|
|
|
if os.execute("mkdir "..thumb_path) ~= 0 then |
|
|
|
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}") |
|
|
|