• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

OpenResty+lua+GraphicsMagick生成缩略图

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

1、安装GraphicsMagick

下载地址:http://sourceforge.net/projects/graphicsmagick/files/graphicsmagick/1.3.19/GraphicsMagick-1.3.19.tar.gz/download?use_mirror=ncu

tar zxvf GraphicsMagick-1.3.19.tar.gz
cd GraphicsMagick-1.3.19
make
make install

安装依赖包Ghostscript,不安装的话加水印会找不到字体

yum install -y ghostscript

 2、配置nginx.conf

location /down/PersonImg {
            set $image_root /usr/local/openresty/nginx/html;
            set $file "$image_root$uri";
            rewrite_by_lua '
                local index = string.find(ngx.var.uri, "([0-9]+)x([0-9]+)");
                local originalUri = string.sub(ngx.var.uri, 0, index-2);
                local area = string.sub(ngx.var.uri, index);
                index = string.find(area, "([.])");
                area = string.sub(area, 0, index-1);
                local image_sizes = {"140x140", "800x800", "90x90"};

                function table.contains(table, element)
                    for _, value in pairs(table) do
                        if value == element then
                            return true
                        end
                    end
                    return false
                end
                if table.contains(image_sizes, area) then
                    local command = "/usr/local/GraphicsMagick/bin/gm convert " .. ngx.var.image_root ..  originalUri  .. " -thumbnail " .. area .. " -gravity center -extent " .. area .. " " .. ngx.var.file;
                    os.execute(command);
                else
                    ngx.exit(401)
                end
            ';
            alias /usr/local/openresty/nginx/html/down/PersonImg/;

        }

3、访问
http://10.10.3.221/down/PersonImg/3AFAE457-FDC8-27D3-E2B5-6C10A145A3A6.jpg.90x90.jpg

4、要加水印的话命令如下

/usr/local/GraphicsMagick/bin/gm convert /usr/local/openresty/nginx/html/down/PersonImg/3AFAE457-FDC8-27D3-E2B5-6C10A145A3A6.jpg -font ArialBold -pointsize 45 -fill red -draw "text 10,10 dsideal" /usr/local/openresty/nginx/html/down/PersonImg/3AFAE457-FDC8-27D3-E2B5-6C10A145A3A61111.jpg

 

 

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
cocos2dx的lua绑定发布时间:2022-07-22
下一篇:
简单版nginxlua完成流量上报于中间件发布时间:2022-07-22
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap