首页 > Web开发 > 详细

[Nginx]使用ngx_http_image_filter_module实现压缩图片为缩略图

时间:2021-05-23 22:43:26      阅读:14      评论:0      收藏:0      [点我收藏+]

ubuntu系统下,先安装ngx_http_image_filter_module这个模块

先看看自己的源

cat /etc/apt/sources.list.d/nginx-stable.list

deb http://nginx.org/packages/ubuntu/ xenial nginx
deb-src http://nginx.org/packages/ubuntu/ xenial nginx

apt-get install -y nginx nginx-module-image-filter

 

在/etc/nginx/nginx.conf 的开头部分引入模块

load_module modules/ngx_http_image_filter_module.so;

 

配置vhost

例如我这个例子,一定注意看if判断部分 , 语法错误也不行,这个就是当传递width和height参数的时候,就按照参数的进行裁剪

    location ~* .*\.(JPG|jpg|gif|png|PNG)$ {
        root /var/www/html/go-fly2;
        # 图片默认高度
       set $width -;  
        # 图片默认高度
        set $height -;  
        if ( $arg_width != "" ) { 
                set $width $arg_width;
        }   
        if ( $arg_height != "" ) { 
                set $height $arg_height;
        }   
        image_filter test;
    
        image_filter resize $width $height; 
        image_filter_buffer 100M;  
        image_filter_jpeg_quality 95; 
} 

https://xxxx/xxxxx.jpg?width=100

类似上面这样调用

[Nginx]使用ngx_http_image_filter_module实现压缩图片为缩略图

原文:https://www.cnblogs.com/taoshihan/p/14801697.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!