Openresty + Lua + graphicsmagick

Source: Internet
Author: User

1. Install 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.gzcd GraphicsMagick-1.3.19makemake install

Install the dependency package ghostscript. If it is not installed, the font cannot be found when adding the watermark.

yum install -y ghostscript

2. Configure 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. Access
Http: // 10.10.3.221/down/personimg/3afae457-fdc8-27d3-e2b5-6c10a145a3a6.jpg.90x90.jpg

4. The command to add a watermark is as follows:

/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

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.