在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):yanue/nginx-lua-GraphicsMagick开源软件地址(OpenSource Url):https://github.com/yanue/nginx-lua-GraphicsMagick开源编程语言(OpenSource Language):Objective-C 41.3%开源软件介绍(OpenSource Introduction):nginx-lua-GraphicsMagickNginx+Lua+GraphicsMagick,实现自定义图片尺寸功能,支持两种模式[固定高宽模式,定高或定宽模式],支持FastDFS文件存储 github地址:https://github.com/yanue/nginx-lua-GraphicsMagick 说明
2016-01-14更新说明
2016-04-22更新说明
文件夹规划img.xxx.com(如/var/www/img)
|-- img1
| `-- 001
| `-- 001.jpg
|-- img2
| `-- notfound.jpg
|-- img3
| `-- 001
| `-- 001.jpg 自定义尺寸后的路径thumb(如/tmp/thumb,可在conf文件里面更改)
`-- img1
`-- 001
|-- 001_200x160.jpg 固定高和宽
|-- 001_-100.jpg 定高
|-- 001_200-.jpg 定宽
链接地址对应关系
访问流程
安装CentOS6 安装过程见 nginx+lua+GraphicsMagick安装 配置依赖
./configure --prefix=/usr/local/nginx \
--user=www \
--group=www \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--error-log-path=/opt/logs/nginx/error.log \
--http-log-path=/opt/logs/nginx/access.log \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_sub_module \
--with-http_flv_module \
--with-http_dav_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-http_addition_module \
--with-http_spdy_module \
--with-pcre \
--with-zlib=../zlib-1.2.8 \
--add-module=../nginx-http-concat \
--add-module=../lua-nginx-module \
--add-module=../ngx_devel_kit \
配置文件说明nginx 配置文件 /etc/nginxvhost 为站点配置lua 为裁切图片处理目录
nginx vhost demo配置server{
listen 80
# set var for thumb pic
set $upload_path /opt/uploads;
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 Yanue'; # 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 /etc/nginx/lua/autoSize.lua; # load lua
}
}
# like: /xx/xx/xx.jpg_100x100.jpg
location ~* ^(.+\.(jpg|jpeg|gif|png))_(\d+)+x(\d+)+\.(jpg|jpeg|gif|png)$ {
root $img_thumbnail_root; # root path for croped img
if (!-f $img_file) { # if file not exists
add_header X-Powered-By 'Nginx+Lua+GraphicsMagick By Yanue'; # 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 /etc/nginx/lua/cropSize.lua; # load lua
}
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
} nginx fastdfs配置server{
listen 80;
server_name xxx.com;
set $img_thumbnail_root /opt/fastdfs/thumb; #set thumb path
set $img_file $img_thumbnail_root$uri; #thumb file
# like:/pic/M00/xx/xx/xx.jpg_100-.jpg or /pic/M00/xx/xx/xx.jpg_-100.jpg
location ~* ^(\/(\w+)(\/M00)(.+\.(jpg|jpeg|gif|png)))_((\d+\-)|(\-\d+))\.(jpg|jpeg|gif|png)$ {
root $img_thumbnail_root; # root path for croped img
set $fdfs_group_root /opt/fastdfs/$2/store0/data; #set fastdfs group path $2
if (!-f $img_file) { # if thumb file not exists
add_header X-Powered-By 'Nginx+Lua+GraphicsMagick By Yanue'; # header for test
add_header file-path $request_filename; # header for test
set $request_filepath $fdfs_group_root$4; # origin_img full path:/document_root/1.gif
set $img_size $6; # img width or height size depends on uri : img size like "-100" or "100-", "-" means auto size
set $img_ext $5; # file ext
content_by_lua_file /etc/nginx/lua/autoSize.lua; # load auto width or height crop Lua file
}
}
# like:/pic/M00/xx/xx/xx.jpg_200x100.jpg
location ~* ^(\/(\w+)(\/M00)(.+\.(jpg|jpeg|gif|png))_(\d+)+x(\d+)+\.(jpg|jpeg|gif|png))$ {
root $img_thumbnail_root; # root path for croped img
set $fdfs_group_root /opt/fastdfs/$2/store0/data; #set fastdfs group path $2
if (!-f $img_file) { # if thumb file not exists
add_header X-Powered-By 'Nginx+Lua+GraphicsMagick By Yanue'; # header for test
add_header file-path $request_filename; # header for test
set $request_filepath $fdfs_group_root$4; # real file path
set $img_width $6; # img width
set $img_height $7; # img height
set $img_ext $5; # file ext
content_by_lua_file /etc/nginx/lua/cropSize.lua; # load crop Lua file
}
}
location /pic/M00 {
alias /opt/fastdfs/pic/store0/data;
ngx_fastdfs_module;
}
location /chat/M00 {
alias /opt/fastdfs/chat/store0/data;
ngx_fastdfs_module;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
} 最后说明
参考:https://github.com/hopesoft/nginx-lua-image-module |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论