Nginx自带的image_filter_module模块是可以对图片进行编辑处理,包括可以实现水印功能。老蒋有看到GITHUB有网友进行二次开发的Nginx-image-filter-watermark模块可以较为方便的给Nginx环境中的图片进行自动水印效果,我们看看如何操作的。
第一、基本配置
1、Nginx要求
nginx >= 1.11.6
2、需要开启
image_filter watermark;
image_filter_watermark_width_from 300;
image_filter_watermark_height_from 400;image_filter_watermark "PATH_TO_FILE";
image_filter_watermark_position center-center; # top-left|top-right|bottom-right|bottom-left|right-center|left-center|bottom-center|top-center|center-center|center-random`
第二、安装模块
模块地址:https://github.com/intaro/nginx-image-filter-watermark/archive/master.zip
我们需要下载到本地然后编译至Nginx.
/configure --with-http_image_filter_module
make
make install
第三、配置使用
location /img/ {
image_filter watermark;image_filter_watermark "PATH_TO_FILE";
image_filter_watermark_position center-center;
}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 /PATH_TO_STATIC/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 watermarkimage_filter_watermark "PATH_TO_FILE";
image_filter_watermark_position center-center;
}
我们可以测试下效果。
本文出处:老蒋部落 » 使用Nginx-image-filter-watermark模块自动给图片加水印 | 欢迎分享( 公众号:老蒋朋友圈 )