使用nginx为图片进行水印操作
2015-12-04 13:34
567 查看
打水印版nginx安装过程(centos)
1. 安装依赖组件
sudo yum install gd-devel pcre-devel libcurl-devel
2. 下载nginx
(1) 下载 wget http://nginx.org/download/nginx-1.9.6.tar.gz
(2)解压 tar -zxvf nginx-1.9.6.tar.gz
(3) 进入目录 cd nginx-1.9.6
3. 下载水印功能源代码
https://github.com/intaro/nginx-image-filter-watermark
点击download zip下载
伦理片 http://www.dotdy.com/
4. 覆盖nginx中的代码将下载的zip解压,将其中的ngx_http_image_filter_module.c文件覆盖到nginx源码中(/src/http/modules/http_image_filter_module.c)
5. 编译安装nginx(假设nginx源码在usr/local/nginx/nginx-1.9.6中)
./configure --with-http_image_filter_module
--with-http_stub_status_module --with-http_ssl_module --with-http_sub_module --prefix=/usr/local/nginx/nginx-1.9.6
make
make install
6. 配置
Example Usage
Base Usage:
location /img/ {
image_filter watermark;#开启水印
image_filter_watermark "PATH_TO_FILE";#水印文件位置
image_filter_watermark_position center-center;#水印位置
image_filter_jpeg_quality 95;#图片质量
image_filter_buffer 20M;#缓存
image_filter_watermark_width_from 400; # 打水印的图片最小宽带,只有大于这个宽带的才会打水印
image_filter_watermark_height_from 400; #打水印的图片最小高度,只有大于这个高度的才会打水印
}
Usage with resize and crop:
location ~ ^/r/(\d+|-)x(\d+|-)/c/(\d+|-)x(\d+|-)/(.+) {
set $resize_width $1;
set $resize_height $2;
set $crop_width $3;
set $crop_height $4;
alias /Users/goshan/Sites/Zot/Zot/web/$5;
try_files "" @404;
image_filter resize $resize_width $resize_height;
image_filter crop $crop_width $crop_height;
image_filter_jpeg_quality 95;
image_filter_buffer 2M;
image_filter_watermark_width_from 400; # Minimal width (after resize) of when to use watermark
image_filter_watermark_height_from 400; # Minimal height (after resize) of when to use watermark
image_filter_watermark "PATH_TO_FILE";
image_filter_watermark_position center-center;
7. 注意事项
(1) 水印文件必须是背景透明的文件
(2) 如果要打水印的图片文件会很大,需将image_filter_buffer设置大一些,比如20M
影音先锋电影 http://www.iskdy.com/
相关文章推荐
- install nginx in centos
- install nginx in centos
- nginx 的安装
- nginx 源码学习笔记(二十三)—— event 模块(四) ——timer红黑树
- nginx 源码学习笔记(二十二)—— event 模块(三) ——epoll模块
- nginx 源码学习笔记(二十一)—— event 模块(二) ——事件驱动核心ngx_process_events_and_timers
- nginx 源码学习笔记(二十)—— event 模块(一) ——初始化
- nginx 源码学习笔记(十九)—— nginx启动过程函数调用图
- nginx 源码学习笔记(十八)—— ngx_add_inherited_sockets 继承的sockets
- CentOS+nginx+uwsgi+Python+django 环境搭建
- Centos6.5安装及简单配置nginx
- Nginx代理功能(未完)
- nginx 源码学习笔记(十七)—— ngx_worker_process_cycle子进程执行
- 【django】Nginx+uWSGI+Django部署我的博客网站
- nginx是以多进程的方式来工作的
- 使用vim打开某文件一直出现Swap file ".nginx.conf.swp" already exists!
- nginx防止SQL注入规则
- Nginx加载多个CPU核心,worker_cpu_affinity
- nginx 全面优化 负载均衡
- lnmp全面优化集合nginx+mysql+php