curl -R -O http://www.lua.org/ftp/lua-5.3.5.tar.gz tar zxf lua-5.3.5.tar.gz cd lua-5.3.5 make linux test
编译安装LuaJIT
1 2 3 4 5 6 7
curl -R -O http://luajit.org/download/LuaJIT-2.0.5.tar.gz tar -zxvf LuaJIT-2.0.5.tar.gz cd LuaJIT-2.0.5 make -j2 export LUAJIT_LIB=/usr/local/lib export LUAJIT_INC=/usr/local/include/luajit-2.0 ln -s /usr/local/lib/libluajit-5.1.so.2 /lib64/libluajit-5.1.so.2
安装GraphicsMagick
1 2 3 4 5
wget ftp://ftp.graphicsmagick.org/pub/GraphicsMagick/1.3/GraphicsMagick-1.3.31.tar.gz tar xzvf GraphicsMagick-1.3.31.tar.gz cd GraphicsMagick-1.3.31 ./configure --prefix=/usr/local/GraphicsMagick --enable-shared make && make install
jaychang@tengine:/usr/local/tengine/sbin$ ./nginx -t ./nginx: error while loading shared libraries: libluajit-5.1.so.2: cannot open shared object file: No such file or directory
# add support for img which has query params, # like: xxx.jpg?a=b&c=d_750x750.jpg if ($args ~* "^([^_]+)_(d+)+x(d+)+.(jpg|jpeg|gif|png)$") { set $w $2; set $h $3; set $img_ext $4;
# set var for thumb pic set $upload_path /var/filebase; set $img_original_root $upload_path;# original root; set $img_thumbnail_root $upload_path/cache/thumb; set $img_file $img_thumbnail_root$uri;
# like:/xx/xx/xx.jpg_100-.jpg or /xx/xx/xx.jpg_-100.jpg location ~* ^(.+.(jpg|jpeg|gif|png))_((d+-)|(-d+)).(jpg|jpeg|gif|png)$ { root $img_thumbnail_root; # root path for croped img set $img_size $3;
if (!-f $img_file) { # if file not exists add_header X-Powered-By 'Nginx+Lua+GraphicsMagick By Botao'; # header for test add_header file-path $request_filename; # header for test set $request_filepath $img_original_root$1; # origin_img full path:/document_root/1.gif set $img_size $3; # img width or height size depends on uri set $img_ext $2; # file ext content_by_lua_file /usr/local/tengine/lua/autoSize.lua; # load lua } }
if (!-f $img_file) { # if file not exists add_header X-Powered-By 'Nginx+Lua+GraphicsMagick By Botao'; # header for test add_header file-path $request_filename; # header for test set $request_filepath $img_original_root$1; # origin_img file path set $img_width $3; # img width set $img_height $4; # height set $img_ext $5; # file ext content_by_lua_file /usr/local/tengine/lua/cropSize.lua; # load lua } }
# if need (all go there) location ~* /upload { root $img_original_root; }
-- 检测路径是否目录 local function is_dir(sPath) if type(sPath) ~= "string" then return false end
local response = os.execute("cd " .. sPath) if response == 0 then return true end return false end
-- 文件是否存在 function file_exists(name) local f = io.open(name, "r") if f ~= nil then io.close(f) return true else return false end end
-- 获取文件路径 function getFileDir(filename) return string.match(filename, "(.+)/[^/]*%.%w+$") --*nix system end
-- 获取文件名 function strippath(filename) return string.match(filename, ".+/([^/]*%.%w+)$") -- *nix system end
--去除扩展名 function stripextension(filename) local idx = filename:match(".+()%.%w+$") if (idx) then return filename:sub(1, idx - 1) else return filename end end
--获取扩展名 function getExtension(filename) return filename:match(".+%.(%w+)$") end
function getImgSize(img)
end
-- 判断尺寸是否合法 -- check image size function table.contains(table, element) for _, value in pairs(table) do