前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >[Nginx]使用ngx_http_image_filter_module实现压缩图片为缩略图

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

作者头像
唯一Chat
发布2021-05-27 10:48:51
9510
发布2021-05-27 10:48:51
举报
文章被收录于专栏:陶士涵的菜地陶士涵的菜地

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

代码语言:javascript
复制
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参数的时候,就按照参数的进行裁剪

代码语言:javascript
复制
    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

类似上面这样调用

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2021-05-23 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档