ubuntu under nginx configuration image scaling ngx_image_thumb-- turn

ngx_image_thumb in nginx is used to generate thumbnails module, thumbnails are many ways to survive, before also wrote " nginx configuration to generate thumbnails " and found people develop a module, the author of the document was written on github detail, I will copy over. The future will do a test.

characteristic

This nginx module main function is to request the thumbnail picture / watermarking, watermark support text and image watermark. Support for custom fonts, text size, transparency of watermark, the watermark position to judge whether the original image is greater than the specified size before treatment, etc.

1. Compile method

Before compiling Please make sure your system has the libcurl-dev libgd2-dev libpcre- dev dependent libraries to install
1.1 Debian / Ubuntu system, for example

# If you do not have the relevant environmental GCC only need to perform
$ sudo install APT-GET Build-Essential M4 autoconf automake the make
$ sudo install libgd2 APT-GET-noxpm-dev libcurl4-libpcre3 OpenSSL-dev-dev

1.2 CentOS /RedHat / Fedora

# Make sure you have installed automake autoconf M4 gcc
$ sudo yum install gd-devel PCRE-devel libcurl-devel

1.3 FreeBSD / NetBSD / OpenBSD

# Not much to say, they used the port libcurl-dev libgd2-dev libpcre- dev installed on it
# make sure you have installed before compiling gcc automake autoconf m4

1.4 Windows

# Also supported, but too much to modify the code, including Nginx itself, using VC ++ to compile
# can be bothered to compile a cygwin. Still I do not recommend you do that with Unix / Linux operating system now.

2. nginx / tengine installation

Nginx is selected Tengine, your own look, choose one of the two
2.1 download Tengine

?
1
2
3
# wget http://tengine.taobao.org/download/tengine-1.4.5.tar.gz
# tar -zxvf tengine-1.4.5.tar.gz
# cd tengine-1.4.5

2.2 Download Nginx

?
1
2
3
# wget http://nginx.org/download/nginx-1.4.0.tar.gz
# tar -zxvf nginx-1.4.0.tar.gz
# cd nginx-1.4.0

Mounting module 2.3

?
1
2
3
4
5
# wget https://github.com/3078825/nginx-image/archive/master.zip
# unzip master.zip
# ./configure --add-module=./nginx-image-master
# make
# make install

3. Configuration

?
1
2
3
4
5
6
7
location / {
  root html;
 
#添加以下配置
  image on;
  image_output on;
  }

4. Parameters

image on / off thumbnail feature is turned off by default
image_backend on / off mirroring service is turned on when this feature is turned on, request directory does not exist in the picture (original judgment), will automatically download the original image from the image server address
image_backend_server mirror server address
image_output on / off whether or not to generate images directly after processing and output default OFF
image_jpeg_quality quality JPEG images generated default value of 75 75
image_water ON / OFF function is turned watermark
image_water_type 0/1 0 watermark types: image watermark 1: text watermark
image_water_min 300 is 300 image width 300 height 300 only add watermark
image_water_pos 0-9 watermark position default 90 random positions, one of the top left and the 2 is the top center, 3 is a top right home, 4 is a central left, 5 of the central center, middle right home for the 6, 7 to the bottom of the left and 8 to the bottom of the center, 9 to the bottom right of abode
image_water_file watermark files (jpg / png / gif), the watermark image is absolute or relative path
image_water_transparent watermark transparency, default 20
image_water_text watermark text "Power By Vampire"
image_water_font_size The default print size 5
image_water_font text watermark font file path
image_water_color watermark text color, default # 000000

Call Description

It is assumed that your nginx access address http://127.0.0.1/

And there is a test.jpg pictures nginx web root directory

By accessing

http://127.0.0.1/test.jpg!c300x200.jpg will generate / output test.jpg thumbnail of 300 × 200

Where c is a parameter generated thumbnail images, thumbnail 300 is generated is generated thumbnail width 200 height

You can generate a total of four different types of thumbnails.

Support jpeg / png / gif (Gif after generation becomes a static picture)

C parameter according to the request from the aspect ratio of the image height 10% start capturing images, and zoom / zoom into a specified size (size of the thumbnail image is equal to the requested width and height)

M Request parameter as the aspect ratio picture is centered theme, then zoom / zoom into a specified size (size of the thumbnail image is equal to the requested width and height)

Request parameter as the aspect ratio of T scaled / amplified to a specified size (size of the thumbnail image may be less than the requested width and height)

W Request parameter as the aspect ratio of the zoom / zoom into the designated size, the space filled with a white background color (the size of the thumbnail image is equal to the requested width and height)

5. Call Example

http://127.0.0.1/test.jpg!c300x300.jpg

http://127.0.0.1/test.jpg!t300x300.jpg

http://127.0.0.1/test.jpg!m300x300.jpg

http://127.0.0.1/test.jpg!w300x300.jpg

http://127.0.0.1/test.c300x300.jpg

http://127.0.0.1/test.t300x300.jpg

http://127.0.0.1/test.m300x300.jpg

http://127.0.0.1/test.w300x300.jpg

6. Finally

Thumbnail This module is generated in real time, if your website traffic is relatively large, is bound to cause nginx server load is too high for this problem, you can refer to our operation and maintenance write a few articles before survival time, were kept hard disk and Redis. " nginx real-time to generate a thumbnail to the hard disk ," " srcache_nginx + Redis caching system to build "

Reference article

Project Address: https://github.com/3078825/nginx-image/

ngx_image_thumb in nginx is used to generate thumbnails module, thumbnails are many ways to survive, before also wrote " nginx configuration to generate thumbnails " and found people develop a module, the author of the document was written on github detail, I will copy over. The future will do a test.

characteristic

This nginx module main function is to request the thumbnail picture / watermarking, watermark support text and image watermark. Support for custom fonts, text size, transparency of watermark, the watermark position to judge whether the original image is greater than the specified size before treatment, etc.

1. Compile method

Before compiling Please make sure your system has the libcurl-dev libgd2-dev libpcre- dev dependent libraries to install
1.1 Debian / Ubuntu system, for example

# If you do not have the relevant environmental GCC only need to perform
$ sudo install APT-GET Build-Essential M4 autoconf automake the make
$ sudo install libgd2 APT-GET-noxpm-dev libcurl4-libpcre3 OpenSSL-dev-dev

1.2 CentOS /RedHat / Fedora

# Make sure you have installed automake autoconf M4 gcc
$ sudo yum install gd-devel PCRE-devel libcurl-devel

1.3 FreeBSD / NetBSD / OpenBSD

# Not much to say, they used the port libcurl-dev libgd2-dev libpcre- dev installed on it
# make sure you have installed before compiling gcc automake autoconf m4

1.4 Windows

# Also supported, but too much to modify the code, including Nginx itself, using VC ++ to compile
# can be bothered to compile a cygwin. Still I do not recommend you do that with Unix / Linux operating system now.

2. nginx / tengine installation

Nginx is selected Tengine, your own look, choose one of the two
2.1 download Tengine

?
1
2
3
# wget http://tengine.taobao.org/download/tengine-1.4.5.tar.gz
# tar -zxvf tengine-1.4.5.tar.gz
# cd tengine-1.4.5

2.2 Download Nginx

?
1
2
3
# wget http://nginx.org/download/nginx-1.4.0.tar.gz
# tar -zxvf nginx-1.4.0.tar.gz
# cd nginx-1.4.0

Mounting module 2.3

?
1
2
3
4
5
# wget https://github.com/3078825/nginx-image/archive/master.zip
# unzip master.zip
# ./configure --add-module=./nginx-image-master
# make
# make install

3. Configuration

?
1
2
3
4
5
6
7
location / {
  root html;
 
#添加以下配置
  image on;
  image_output on;
  }

4. Parameters

image on / off thumbnail feature is turned off by default
image_backend on / off mirroring service is turned on when this feature is turned on, request directory does not exist in the picture (original judgment), will automatically download the original image from the image server address
image_backend_server mirror server address
image_output on / off whether or not to generate images directly after processing and output default OFF
image_jpeg_quality quality JPEG images generated default value of 75 75
image_water ON / OFF function is turned watermark
image_water_type 0/1 0 watermark types: image watermark 1: text watermark
image_water_min 300 is 300 image width 300 height 300 only add watermark
image_water_pos 0-9 watermark position default 90 random positions, one of the top left and the 2 is the top center, 3 is a top right home, 4 is a central left, 5 of the central center, middle right home for the 6, 7 to the bottom of the left and 8 to the bottom of the center, 9 to the bottom right of abode
image_water_file watermark files (jpg / png / gif), the watermark image is absolute or relative path
image_water_transparent watermark transparency, default 20
image_water_text watermark text "Power By Vampire"
image_water_font_size The default print size 5
image_water_font text watermark font file path
image_water_color watermark text color, default # 000000

Call Description

It is assumed that your nginx access address http://127.0.0.1/

And there is a test.jpg pictures nginx web root directory

By accessing

http://127.0.0.1/test.jpg!c300x200.jpg will generate / output test.jpg thumbnail of 300 × 200

Where c is a parameter generated thumbnail images, thumbnail 300 is generated is generated thumbnail width 200 height

You can generate a total of four different types of thumbnails.

Support jpeg / png / gif (Gif after generation becomes a static picture)

C parameter according to the request from the aspect ratio of the image height 10% start capturing images, and zoom / zoom into a specified size (size of the thumbnail image is equal to the requested width and height)

M Request parameter as the aspect ratio picture is centered theme, then zoom / zoom into a specified size (size of the thumbnail image is equal to the requested width and height)

Request parameter as the aspect ratio of T scaled / amplified to a specified size (size of the thumbnail image may be less than the requested width and height)

W Request parameter as the aspect ratio of the zoom / zoom into the designated size, the space filled with a white background color (the size of the thumbnail image is equal to the requested width and height)

5. Call Example

http://127.0.0.1/test.jpg!c300x300.jpg

http://127.0.0.1/test.jpg!t300x300.jpg

http://127.0.0.1/test.jpg!m300x300.jpg

http://127.0.0.1/test.jpg!w300x300.jpg

http://127.0.0.1/test.c300x300.jpg

http://127.0.0.1/test.t300x300.jpg

http://127.0.0.1/test.m300x300.jpg

http://127.0.0.1/test.w300x300.jpg

6. Finally

Thumbnail This module is generated in real time, if your website traffic is relatively large, is bound to cause nginx server load is too high for this problem, you can refer to our operation and maintenance write a few articles before survival time, were kept hard disk and Redis. " nginx real-time to generate a thumbnail to the hard disk ," " srcache_nginx + Redis caching system to build "

Reference article

Project Address: https://github.com/3078825/nginx-image/

Guess you like

Origin www.cnblogs.com/51ma/p/12034755.html