在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
ngx_image_thumb模块生成缩略图 ngx_image_thumb是nginx中用来生成缩略图的模块,生存缩略图的方法很多,本nginx模块主要功能是对请求的图片进行缩略/水印处理,支持文字水印和图片水印。支持自定义字体,文字大小,水印透明度,水印位置,判断原图是否是否大于指定尺寸才处理等等。 # 如果你没有安装GCC相关环境才需要执行 $ sudo apt-get install build-essential m4 autoconf automake make $ sudo apt-get install libgd2-noxpm-dev libcurl4-openssl-dev libpcre3-dev 1.2 CentOS /RedHat / Fedora # 请确保已经安装了gcc automake autoconf m4 $ sudo yum install gd-devel pcre-devel libcurl-devel 1.3 FreeBSD / NetBSD / OpenBSD # wget http://tengine.taobao.org/download/tengine-1.4.5.tar.gz # tar -zxvf tengine-1.4.5.tar.gz # cd tengine-1.4.5 2.2 下载Nginx # wget http://nginx.org/download/nginx-1.4.0.tar.gz # tar -zxvf nginx-1.4.0.tar.gz # cd nginx-1.4.0 2.3 安装模块 # wget https://github.com/3078825/nginx-image/archive/master.zip # unzip master.zip # ./configure --add-module=./nginx-image-master # make # make install 3. 配置 location / { root html; #添加以下配置 image on; image_output on; } 4. 参数
4.1调用说明 这里假设你的nginx 访问地址为 http://127.0.0.1/ http://127.0.0.1/test.jpg!c300x300.jpg http://127.0.0.1/test.jpg!t300x300.jpg http://127.0.0.1/test.jpg!m300x300.jpg http://127.0.0.1/test.jpg!w300x300.jpg http://127.0.0.1/test.c300x300.jpg http://127.0.0.1/test.t300x300.jpg http://127.0.0.1/test.m300x300.jpg http://127.0.0.1/test.w300x300.jpg nginx实时生成缩略图到硬盘上 # mkdir /data/site_cache/ 2. 修改nginx配置 location ~* ^/resize { root /data/site_cache/$server_name; set $width 150; set $height 100; set $dimens ""; if ($uri ~* "^/resize_(\d+)x(\d+)/(.*)" ) { set $width $1; set $height $2; set $image_path $3; set $demins "_$1x$2"; } if ($uri ~* "^/resize/(.*)" ) { set $image_path $1; } set $image_uri image_resize/$image_path?width=$width&height=$height; if (!-f $request_filename) { proxy_pass http://127.0.0.1/$image_uri; break; } proxy_store /data/site_cache/$server_name/resize$demins/$image_path; proxy_store_access user:rw group:rw all:r; proxy_set_header Host $host; expires 30d; access_log off; } location /image_resize { alias /data/site/$server_name/; image_filter resize $arg_width $arg_height; image_filter_jpeg_quality 75; access_log off; } 生成缩略图流程如下: |
请发表评论