make && make install ImageMagick
http://www.imagemagick.org/
Modify
nginx-server.conf
convert_bin imagemagick_install_path/bin/convert
rewrite_by_lua_file nginx-imagemagick.lua save path
if want to allow more image>image_sizes variable in nginx-imagemagick.lua
server
{
listen 80;
server_name upload.qq.com;
index index.html index.htm index.php;
root /h1/upload.qq.com;
location ~ ^(.+\.php)(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param SCRIPT_FILENAME /path/to/php$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fcgi.conf;
}
rewrite ^/attachment/image/(.*).jpg$ /attachment/image/$1.jpg!0x0 last;#处理原始图显示为0x0图
# rewrite ^/images/(.*).jpg ^/images/$1.jpg!0x0 last;
location /attachment/image/ {
set $image_root "/htdoc/upload.qq.com";
set $file "$image_root$uri";
set $convert_bin "/usr/local/bin/convert";
if (!-f $file)
{
rewrite_by_lua_file /usr/local/webserver/nginx/conf/nginx-imagemagick.lua;
}
expires max;
}
location ~ .*\.(js|css)?$
{
expires max;
}
}
下面是lua代码 nginx-imagemagick.lua:
-- http://domain.com/111/photo/201411/05/5459e306820af926411357_320x320.jpg
-- config
local image_sizes = { "640x640", "320x320", "124x124", "140x140", "64x64", "60x60", "32x32", "0x0" }
-- parse uri
function parseUri(uri)
local _, _, name, ext,> --ngx.header.content_type = "text/plain";
--ngx.say(name,size);
if name and>
return ngx.var.image_root .. name .. ext,> else
return "",""
end
end
function fileExists(name)
local f = io.open(name, "r")
if f ~= nil then
io.close(f)
return true
else
return false
end
end
--ngx.header.content_type = "text/plain";
--ngx.say(name);
function> for _, value in pairs(image_sizes) do
if value ==> return true
end
end
return false
end
--ngx.header.content_type = "text/plain";
--ngx.say(size);
function resize()
local ori_filename,> --ngx.header.content_type = "text/plain";
--ngx.say(ori_filename,size);
if fileExists(ori_filename) == false or> ngx.exit(404)
end
local command = '';