File tree Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change 1+ -- nginx lua thumbnail module
2+ -- last update : 2014/11/3
3+ -- version : 0.5.0
4+ -- created by yanne
5+
16-- 检测路径是否目录
27local function is_dir (sPath )
38 if type (sPath ) ~= " string" then return false end
4348-- 开始执行
4449-- ngx.log(ngx.ERR, getFileDir(ngx.var.file));
4550
46- local gm_path = ' /usr/local/bin/ gm'
51+ local gm_path = ' gm'
4752
4853-- check image dir
4954if not is_dir (getFileDir (ngx .var .file )) then
5055 os.execute (" mkdir -p " .. getFileDir (ngx .var .file ))
5156end
5257
53- -- 如果原始文件存在,则缩放(以最小边)
58+ -- 裁剪后保证等比缩图 (缺点:裁剪了图片的一部分)
59+ -- gm convert input.jpg -thumbnail "100x100^" -gravity center -extent 100x100 output_3.jpg
5460if (file_exists (ngx .var .request_filepath )) then
5561 local cmd = gm_path .. ' convert ' .. ngx .var .request_filepath
56- cmd = cmd .. " -resize " .. ngx .var .img_width .. " x" .. ngx .var .img_height
62+ cmd = cmd .. " -thumbnail " .. ngx .var .img_width .. " x" .. ngx .var .img_height .. " ^"
63+ cmd = cmd .. " -gravity center -extent " .. ngx .var .img_width .. " x" .. ngx .var .img_height
5764 cmd = cmd .. " +profile \" *\" " .. ngx .var .file ;
5865 ngx .log (ngx .ERR , cmd );
5966 os.execute (cmd );
6067 ngx .exec (ngx .var .uri );
6168else
6269 ngx .exit (ngx .HTTP_NOT_FOUND );
6370end
64-
You can’t perform that action at this time.
0 commit comments