Openresty (Nginx) +lua+graphicsmagick for thumbnail function

Source: Internet
Author: User

http://www.hopesoft.org/blog/?p=1188

2. Usage

The original picture is input.jpg, size: 160x120

1) Only zoom out not to enlarge

1 GM convert input. JPG -resize "500x500>" output_1. JPG

Adds a "Zoom out" operation only if the width and height of the picture are greater than the given width and height.
The resulting picture size is: 160x120, not working
If not added, it will cause the picture to be magnified.

2) equal ratio (disadvantage: produce white edge)

1 GM convert input. JPG -thumbnail "100x100" output_1. JPG

The resulting picture size is: 100x75

3) non-equal ratio thumbnail, by the given parameter thumbnail (disadvantage: aspect ratio will change)

1 GM convert input. JPG -thumbnail "100x100!" output_2. JPG

The resulting picture size is: 100x100

4) cut to ensure that the ratio of the image (disadvantage: cropped part of the picture)

1 gm convert input< Span class= "Crayon-sy". jpg -thumbnail "100x100^" -gravity center - extent 100x100 Span class= "crayon-v" >output_3. JPG

The resulting picture size is: 100x100, which also guarantees the proportions. But the picture has been cut, cutting the picture left and right to reach 1:1

5) After filling to ensure the equal ratio of the image (disadvantage: To fill the color, and the first method is basically the same)

1 gm convert input< Span class= "Crayon-sy". jpg -thumbnail "100x100" - background gray -< Span class= "crayon-e" >gravity center -extent 100x100 output_4. JPG

The resulting picture size is: 100x100, which also guarantees the proportions without any cropping of the picture, and the missing part is populated with the specified color.

6) combination of cropping and filling (Cons: Worst method)

1 gm convert input< Span class= "Crayon-sy". jpg -thumbnail "10000@ -background gray Span class= "Crayon-o" >-gravity center -extent 100x100 output_5. JPG

The resulting picture size is: 100x100, which guarantees the size and scale, 10000 of which is the product of 100x100, and a balance between padding and cropping.

7) Bit depth 32 to 24
ie6,7,8 does not support the display of "bit depth 32" images, but IE9, Firefox, Google Chrome can be displayed.
Use GM to convert the "bit depth 32" picture to "bit depth 24"
Input picture zzz.jpg is "bit depth 32" picture, output picture zzz_out.jpg is "bit depth 24" picture

1 GM convert -resize 100x100 -colorspace RGB zzz. JPG zzz_out. JPG

After the turn, the color of the picture changes slightly.

For more information, please refer to: http://elf8848.iteye.com/blog/382528

Openresty (Nginx) +lua+graphicsmagick for thumbnail function

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.