我们网站有很多地方需要读取图片的属性于是有了下面的代码和limage.so
auth yufei
2016-6-5
ngx_lua快速获取文件大小和图片属性
function F.limage(path,typed)
--读取文件大小和图片宽高
reslimage = {}
if path then
--要先安装https://github.com/keplerproject/luafilesystem/
local lfs = require "lfs"
--local filepath="./ed724426a341d666369a244a2e8c54ad.jpg"
local res=lfs.attributes(path)
local size = res["size"]
if size ~= nil and tonumber(size) >= 0 then
reslimage["size"] = size
end
if typed == "dpi" then
--要先安装https://github.com/yufei6808/limage
local width,height=image_size(path)
if width and height then
reslimage["dpi"] = width.."x"..height
end
end
end
return reslimage
end