Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Build nginx with lua module and call ImageMagick tool to realize the function of real-time cutting and zooming pictures

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

First, install LuaJIT.

Wget http://luajit.org/download/LuaJIT-2.0.5.tar.gz

Tar xf LuaJIT-2.0.5.tar.gz

Cd LuaJIT-2.0.5

Make

Make install

Set the environment variable, do not switch the console after setting, otherwise it will be invalid.

Export LUAJIT_LIB=/usr/local/lib

Export LUAJIT_INC=/usr/local/include/luajit-2.0

Make a soft link and load the module

Ln-s / usr/local/lib/libluajit-5.1.so.2 / usr/lib/libluajit-5.1.so.2

Ldconfig

Second, install ImageMagick tools.

Just use yum to install it, it's very convenient.

Yum install-y ImageMagick

Download nginx and ngx_devel_kit and nginx_lua_module modules, and extract them to the specified path. If nginx is already installed on this machine, please ignore downloading and installing nginx.

Wget http://nginx.org/download/nginx-1.12.0.tar.gz

Wget https://github.com/simpl/ngx_devel_kit/archive/v0.3.0.tar.gz

Wget https://github.com/openresty/lua-nginx-module/archive/v0.10.9rc5.tar.gz

Tar xf nginx-1.12.0.tar.gz & & tar xf v0.3.0.tar.gz & & tar xf v0.10.9rc5.tar.gz

Fourth, compile and install nginx, if the machine already has nginx installed, please ignore the installation, but need to recompile, then backup the old nginx files and get the new one over.

. / configure-- prefix=/usr/local/nginx\

-- add-module= (your decompression path) / ngx_devel_kit-0.3.0\

-- add-module= (your decompression path) / lua-nginx-module-0.10.9rc5

(if nginx is already installed in this machine, add the parameters that your nginx has compiled.)

Make

There is no nginx installed, it is installed by make install directly. Refer to https://cache.yisu.com/upload/information/20200309/32/42291.com$' {

Root / opt/qikanjpg

}

Location ~'/ pdgpath/ ([0-9a murzz] +)\ @ ([0-9] +) x ([0-9] +)\. (gif | jpg | png | jpeg) $'{

Root / opt/qikanjpg

Set $p_w_picpath_root'/ opt/qikanjpg/pdgpath'

Set $fileName $1

Set $width $2

Set $height $3

Set $origin $p_w_picpath_root/$fileName.jpg

Set $file_1 $paired picpathically rootpaced ${fileName} @ ${width} x ${height} .jpg

If (!-f $file_1) {

Rewrite_by_lua'

Local comd = "convert-sample".. ngx.var.width.x ".ngx.var.height.." .ngx.var.width.. ".. ngx.var.file_1

Os.execute (comd)

'

}

}

Location ~'/ pdgpath/ ([0-9a murzz] +)\ @ ([0-9] +) x ([0-9] +) _ f\. (gif | jpg | png | jpeg) $'{

Root / opt/qikanjpg

Set $p_w_picpath_root'/ opt/qikanjpg/pdgpath'

Set $fileName $1

Set $width $2

Set $height $3

Set $origin $p_w_picpath_root/$fileName.jpg

Set $file $paired picpathic root f.jpg ${fileName} @ ${width} x ${height} _ f.jpg

If (!-f $file) {

Rewrite_by_lua'

Local command = "convert-strip-quality 80%-resize".. ngx.var.width.x ".ngx.var.width.." ^-gravity center-crop ".ngx.var.width.x" .ngx.var.width.. "x" .ngx.var.width.. "+ zero" .ngx.var.width.. "" .ngx.var.file ".

Os.execute (command)

'

}

}

7. Visit the pictures and test them.

With the configuration file above, put a 1.jpg in / opt/qikanjpg/pdgpath/.

Original http://(your_server_ip):(your_server_port)/pdgpath/1.jpg

Scale the original http://(your_server_ip):(your_server_port)/pdgpath/1@ width x height equal to the smaller values of width and height. JPG

Scale the original image equally according to the larger values of width and height, and then cut the width and height of the original image again from the middle. One area http://(your_server_ip):(your_server_port)/pdgpath/1@ width x height _ f.jpg

For more cutting functions, please check convert-- help to figure it out and add it to local command =.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report