下载:
软件下载地址:
http://soft.ileiming.com/gm.tar.gz
安装
tar -zxvf gm.tar.gz
tar -zxvf GraphicsMagick-1.3.12.tar.gz
cd GraphicsMagick-1.3.12
./configure –prefix=/usr/local/gm
make && make install
tar -zxvf LuaJIT-2.0.0-beta10.tar.gz
cd LuaJIT-2.0.0-beta10
make && make install PREFIX=/usr/local/lj2
ln -sf luajit-2.0.0-beta10 /usr/local/lj2/bin/luajit
unzip simpl-ngx_devel_kit-v0.2.19-0-g8dd0df5.zip
tar -zxvf chaoslawful-lua-nginx-module-v0.9.2-61-ge4e085f.tar.gz
unzip agentzh-echo-nginx-module-v0.49-1-g84feae9.zip
tar -zxvf ngx_cache_purge-1.6.tar.gz
设置环境变量
export LUAJIT_LIB=/usr/local/lj2/lib
export LUAJIT_INC=/usr/local/lj2/include/luajit-2.0
export LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
GM_HOME=/usr/local/GraphicsMagick-1.3.16;
PATH=$GM_HOME/bin:$PATH;
export PATH
export GM_HOME
使环境变量生效:source /etc/profile
tar -zxvf nginx-1.2.1.tar.gz
cd nginx-1.2.1
./configure –prefix=/usr/local/nginx5 –user=www –group=www –with-http_stub_status_module –add-module=/root/gm/simpl-ngx_devel_kit-8dd0df5 –with-ld-opt=-Wl,-rpath,/usr/local/lj2/lib –add-module=/root/gm/ngx_cache_purge-1.6 –with-http_perl_module –add-module=/root/gm/chaoslawful-lua-nginx-module-e4e085f –add-module=/root/gm/agentzh-echo-nginx-module-84feae9 –with-pcre
如果报错,很可能是没有安装lua和lua-devel
直接yum安装即可:# yum install lua lua-devel
##########################################
nginx配置文件
server {
listen 80;
server_name 192.168.1.199;
root /usr/local/nginx5/html/test;
index index.html index.htm index.php;
location /image/ {
set $image_root /usr/local/nginx5/html/test;
set $file $image_root$uri;
set $forward_url "";
if (!-e $file) {
rewrite_by_lua '
local originalUri = nil;
local area = nil;
local index = string.find(ngx.var.uri, "([0-9]+)x([0-9]+)");
local oUIndex = nil;
local fileExtName = nil;
local fileSuffix = nil;
if index ~= nil then
originalUri = string.sub(ngx.var.uri, 0, index-2);
oUIndex = string.find(originalUri,"([.])");
fileExtName = string.sub(originalUri,oUIndex+1);
fileSuffix = string.sub(originalUri,0,oUIndex-1);
area = string.sub(ngx.var.uri, index);
index = string.find(area, "([.])");
if index ~= nil then
area = string.sub(area, 0, index-1);
end;
end;
if originalUri ~= nil then
local command = "/usr/local/gm/bin/gm convert " .. ngx.var.image_root..originalUri .. " -thumbnail " .. area .. " -background gray -gravity center -extent " .. area .." ".. ngx.var.image_root..originalUri .."_" .. area .. "."..fileExtName;
os.execute("echo command "..command .." >>/usr/local/nginx5/html/123.txt");
os.execute(command);
ngx.var.forward_url = fileSuffix.."_thumb."..fileExtName;
else
ngx.var.forward_url = ngx.var.uri;
end;
';
}
}
}
以上配置只是简单的生成缩略图的配置,通过nginx来控制lua还可以实现只生成固定大小的图片或是,还可以调用A文件夹的图片生成到B文件夹内等非常有用的功能
访问用1.jpg_200x200.jpg
发表评论