http_image_filter_module 圖片轉換-實時-效率不高啊

1 http_image_filter_module
http_image_filter_module是nginx提供的集成圖片處理模塊,支持nginx-0.7.54以後的版本,在網站訪問量不是很高磁盤有限不想生成多餘的圖片文件的前提下可,就可以用它實時縮放圖片,旋轉圖片,驗證圖片有效性以及獲取圖片寬高以及圖片類型信息。

1.1 查看有沒有安裝

/usr/local/nginx/sbin/nginx -V

nginx version: nginx/1.5.0
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-17) (GCC)
TLS SNI support enabled
configure arguments: --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --add-module=/usr/local/src/nginx/fastdfs-nginx-module/src

2 模塊說明
image_filter off;
#關閉模塊

image_filter test;
#確保圖片是jpeg gif png否則返415錯誤

image_filter size;
#輸出有關圖像的json格式:例如以下顯示{ “img” : { “width”: 100, “height”: 100, “type”: “gif” } } 出錯顯示:{}

image_filter rotate 90|180|270;
#旋轉指定度數的圖像,參數能夠包括變量,單獨或一起與resize crop一起使用。

image_filter resize width height;
#按比例降低圖像到指定大小,公降低一個能夠還有一個用"-"來表示,出錯415,參數值可包括變量,能夠與rotate一起使用,則兩個一起生效。

image_filter crop width height;
#按比例降低圖像比較大的側面積和還有一側多餘的載翦邊緣,其他和rotate一樣。沒太理解

image_filter_buffer 10M;
#設置讀取圖像緩衝的最大大小,超過則415錯誤。

image_filter_interlace on;
#假設啓用,終於的圖像將被交錯。對於JPEG,終於的圖像將在“漸進式JPEG”格式。

image_filter_jpeg_quality 95;
#設置變換的JPEG圖像的期望質量。可接受的值是從1到100的範圍內。較小的值通常意味着既降低圖像質量,降低數據傳輸,推薦的最大值爲95。參數值能夠包括變量。

image_filter_sharpen 100;
#添加了終於圖像的清晰度。銳度百分比能夠超過100。零值將禁用銳化。參數值能夠包括變量。

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

3 安裝
3.1 安裝gd,HttpImageFilterModule模塊需要依賴gd-devel的支持

yum -y install gd-devel

3.2 將http_image_filter_module包含進來

cd /usr/local/src/nginx

./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --add-module=/usr/local/src/fastdfs/fastdfs-nginx-module/src --with-http_image_filter_module

make && make install

4 配置nginx
4.1 正常縮放

vi /usr/local/nginx/conf/nginx.conf

location ~* /img {
root /data0;
image_filter resize 150 100;
image_filter rotate 90;
}

http://img2.mydomain.com/img/w8.png

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章