日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Nginx >内容正文

Nginx

Nginx图片剪裁模块探究 http_image_filter_module

發布時間:2023/12/6 Nginx 53 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Nginx图片剪裁模块探究 http_image_filter_module 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

#yum install -y gd-devel


Install add http_image_filter_module Module

#./configure --prefix=/usr/local/nginx_image_filter/ --with-http_image_filter_module

#make && make install


use:


off:關閉模塊處理


test:確保圖片是jpeg gif png否則返415錯誤


size:輸出有關圖像的json格式:如下顯示

{ "img" : { "width": 100, "height": 100, "type": "gif" } }

出錯顯示:

{}


rotate 90|180|270:旋轉指定度數的圖像,參數可以包括變量,單獨或一起與resize crop一起使用。


resize width height:按比例減少圖像到指定大小,公減少一個可以另一個用"-"來表示,出錯415,參數值可包含變量,可以與rotate一起使用,則兩個一起生效。


resize width height:按比例減少圖像大小,其它和rotate一樣。


crop width height:按比例減少圖像比較大的側面積和另一側多余的載翦邊緣,其它和rotate一樣。沒太理解


#設置讀取圖像緩沖的最大大小,超過則415錯誤。

syntax:image_filter_buffer size;

default:

image_filter_buffer 1M;

context:http, server, location


#如果啟用,最終的圖像將被交錯。對于JPEG,最終的圖像將在“漸進式JPEG”格式。

syntax:image_filter_interlace on | off;

default:

image_filter_interlace off;

context:http, server, location

This directive appeared in version 1.3.15.


#設置變換的JPEG圖像的期望質量。可接受的值是從1到100的范圍內。較小的值通常意味著既降低圖像質量,減少傳輸數據,推薦的最大值為95。參數值可以包含變量。

syntax:image_filter_jpeg_quality quality;

default:

image_filter_jpeg_quality 75;

context:http, server, location


#增加了最終圖像的清晰度。銳度百分比可以超過100。零值將禁用銳化。參數值可以包含變量。

syntax:image_filter_sharpen percent;

default:

image_filter_sharpen 0;

context:http, server, location


#定義是否應該透明轉換的GIF圖像或PNG圖像與調色板中指定的顏色時,可以保留。透明度的損失將導致更好的圖像質量。在PNG的Alpha通道總是保留透明度。

syntax:image_filter_transparency on|off;

default:

image_filter_transparency on;

context:http, server, location


image_filter resize width height;

Json:


品茶:這比例不知道具體怎么算的測一測。

nginx.conf:

---------------------------------------------------

? ? ? ?location ~* /image {

? ? ? ? ? ? ? ?image_filter resize 200 200;

? ? ? ?}

---------------------------------------------------


測試數據過程:每次重啟nginx 和清瀏覽器緩存并多次刷新


長>寬

Test1:

Test2:





長<寬


品茶:那么就容易理解了:

1、先進么判斷長還是寬哪個像素占的多。

2、長/寬做成一個比例。

3、如果長占像素多就以長為標準,寬為比例。

4、如果寬占像素多就以寬為標準,長為比例。


模擬程序


1 2 3 4 5 6 7 l?=?get(jpg.l) w?=?get(jpg.k) g?=?l?/?w if?l > w: ????print?nginx.l nginx.l/g else: ????print?nginx.w*w w


image_filter rotate 90 | 180 | 270;

品茶:只能用這三個值,不然nginx啟動報錯。分別是左轉倒轉和右轉,逆時針的。

nginx.conf

---------------------------------------------------------

? ? ? ?location ~* /image {

? ? ? ? ? ? ? ?#image_filter resize 500 500;

? ? ? ? ? ? ? ?image_filter rotate 90;

? ? ? ?}

---------------------------------------------------------

逆時針90度 :90

逆時針180度:180

逆時針270度:270

那就明顯了。

resize:圖片完整,比例縮小。

crop:圖片不完整,但完全按我們提供的來。

rotate:旋轉圖片。

測試一下test


test:

{ "img" : { "width": 1920, "height": 1200, "type": "jpeg" } }

test2:

{ "img" : { "width": 1920, "height": 1080, "type": "jpeg" } }

test3:

{ "img" : { "width": 354, "height": 586, "type": "png" } }

輸出json格式,可以用來調用。


image_filter_buffer size;

我們試試超過1M的文件

415 Unsupported Media Type

品茶:這個值看你怎么設了,因為iphone現在拍的原圖基本上是4-8M左右


image_filter_interlace on

品茶:漸進式jpeg沒懂啥意思


image_filter_jpeg_quality quality; #quality:1-100

品茶:這個值控制圖片的質量,影響清晰度


nginx.conf

-----------------------------------------------------------------

? ? ? ?location ~* /image {

? ? ? ? ? ? ? ?image_filter_jpeg_quality 20;

? ? ? ? ? ? ? ?image_filter resize 500 500;

? ? ? ? ? ? ? ?image_filter_buffer 10M;

? ? ? ? ? ? ? ?image_filter_interlace on;

? ? ? ? ? ? ? ?#image_filter rotate 20;

? ? ? ? ? ? ? ?#image_filter crop 200 200;

? ? ? ? ? ? ? ?#image_filter size;

? ? ? ? ? ? ? ?#image_filter test;

? ? ? ?}

------------------------------------------------------------------



品茶:這就是效果


image_filter_sharpen percent;

品茶:銳化比


image_filter_transparency on|off;

品茶:透明損失度


品茶:想了一下寫幾個規則,可能有用。


比如匹配全站所有的結尾圖片

----------------------------------------------

? ? ? ?location ~* \.(jpg|gif|png)$ {

? ? ? ? ? ? ? ?image_filter resize 500 500;

? ? ? ?}

----------------------------------------------


匹配某個目錄所有圖片

----------------------------------------------

? ? ? ?location ~* /image/.*\.(jpg|gif|png)$ {

? ? ? ? ? ? ? ?image_filter resize 500 500;

? ? ? ?}

----------------------------------------------


再比如用url來指定

---------------------------------------------------

? ? ? ?location ~* (.*\.(jpg|gif|png))!(.*)!(.*)$ {

? ? ? ? ? ? ? ?set $width ? ? ?$3;

? ? ? ? ? ? ? ?set $height ? ? $4;

? ? ? ? ? ? ? ?rewrite "(.*\.(jpg|gif|png))(.*)$" $1;

? ? ? ?}


? ? ? ?location ~* .*\.(jpg|gif|png)$ {

? ? ? ? ? ? ? ?image_filter resize $width $height;

? ? ? ?}

---------------------------------------------------

那么效果是:

品茶:是不是很cool,哈哈,更新完畢了。





本文轉自 煮酒品茶 51CTO博客,原文鏈接:http://blog.51cto.com/cwtea/1333142,如需轉載請自行聯系原作者

總結

以上是生活随笔為你收集整理的Nginx图片剪裁模块探究 http_image_filter_module的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。