欢迎访问服务器技术网-www.fuwuqijishu.com

使用Nginx-image-filter-watermark模块自动给图片加水印

运维 fuwuqijishu 2年前 (2022-09-04) 38次浏览 0个评论 扫描二维码

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 watermark

image_filter_watermark “PATH_TO_FILE”;
image_filter_watermark_position center-center;
}

我们可以测试下效果。

喜欢 (0)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

Warning: error_log(/www/wwwroot/fuwiqijishu/wp-content/plugins/spider-analyser/#log/log-2222.txt): failed to open stream: No such file or directory in /www/wwwroot/fuwiqijishu/wp-content/plugins/spider-analyser/spider.class.php on line 2900