nginx使用http_image_filter_module模块动态生成指定大小图片

安装依赖

yum -y install gd-devel openssl-devel

编译安装

 ./configure --prefix=/usr/local/nginx_server  --with-openssl=/usr/local --with-pcre --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-http_image_filter_module --with-http_slice_module --with-mail --with-threads --with-file-aio --with-stream --with-mail_ssl_module --with-stream_ssl_module --with- --with-http_image_filter_module ;

主要配置

location ~* /img/(.+)_(\d+)x(\d+)\.(jpg|jpeg|gif|png)$ {
        set $w $2;
        set $h $3;
        image_filter resize $w $h;
        image_filter_buffer 30M; 
        image_filter_interlace on;
        image_filter_jpeg_quality 80;
        try_files /$1.$4 /notfound.jpg;
        expires 1d;
        add_header 'Access-Control-Allow-Origin' '*';
        add_header 'Access-Control-Allow-Credentials' 'true';
        alias /mnt/ ; 
    }

生成图片

#生成100x100图片
curl http://192.168.1.5/img/dsfs_100x100.jpg
#生成300x300图片
curl http://192.168.1.5/img/dsfs_300x300.jpg
posted @   时光煮酒丶  阅读(115)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
点击右上角即可分享
微信分享提示