二维码
搬瓦工 locvps

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;
}

我们可以测试下效果。出处:https://www.itbulu.com

locvps
评论专区
  • 昵 称必填
  • 邮 箱必填
  • 网 址选填
◎已有 1 人评论
  • VPS科普网  发表于 4周前
    1楼

    请保留出处:https://www.itbulu.com/nginx-image-filter-watermark.html

BudgetVM
作者介绍
总干事

总干事

总干事作为本站编辑,主要负责VPS优惠、域名优惠和站长百科三个栏目。
80vps henghost
budgetvm sugarhosts
二维码

分享:

支付宝

微信