使用nginx为图片进行水印操作

打水印版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下载
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
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值