1. <strong id="7actg"></strong>
    2. <table id="7actg"></table>

    3. <address id="7actg"></address>
      <address id="7actg"></address>
      1. <object id="7actg"><tt id="7actg"></tt></object>

        Nginx Image Module圖片縮略圖 水印處理

        聯(lián)合創(chuàng)作 · 2023-10-01 15:40

        本nginx模塊主要功能是對請求的圖片進(jìn)行縮略/水印處理,支持文字水印和圖片水印。
        支持自定義字體,文字大小,水印透明度,水印位置。
        判斷原圖是否是否大于指定尺寸才處理。 ....等等
        編譯方法

        編譯前請確認(rèn)您的系統(tǒng)已經(jīng)安裝了libcurl-dev libgd2-dev libpcre-dev 依賴庫

        Debian / Ubuntu 系統(tǒng)舉例

        # 如果你沒有安裝GCC相關(guān)環(huán)境才需要執(zhí)行
        $ sudo apt-get install build-essential m4 autoconf automake make 
        $ sudo apt-get install libgd2-noxpm-dev libcurl4-openssl-dev libpcre3-dev
        CentOS /RedHat / Fedora

        # 請確保已經(jīng)安裝了gcc automake autoconf m4 
        $ sudo yum install gd-devel pcre-devel libcurl-devel 
        FreeBSD / NetBSD / OpenBSD

        # 不多說了,自己用port 把libcurl-dev libgd2-dev libpcre-dev 裝上吧
        # 編譯前請確保已經(jīng)安裝gcc automake autoconf m4 
        Windows

        # 也支持的,不過要修改的代碼太多了,包括Nginx本身,用VC++來編譯
        # 嫌麻煩可以用cygwin來編譯。還是不建議你這么做了,用Unix/Linux操作系統(tǒng)吧。
        下載nginx / tengine 源代碼

        然后下載本模塊代碼,并放在nginx源代碼目錄下

        選Nginx還是Tengine,您自己看,兩者選其一

        # 下載Tengine
        $ 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
        # 下載Nginx
        $ wget http://nginx.org/download/nginx-1.4.0.tar.gz
        $ tar -zxvf nginx-1.4.0.tar.gz
        $ cd nginx-1.4.0
        $ wget https://github.com/3078825/nginx-image/archive/master.zip
        $ unzip master.zip
        $ ./configure --add-module=./nginx-image-master
        $ make
        $ sudo make install 
        配置方法


        打開 nginx.conf

        vim /etc/nginx/nginx.conf 

        # 該路徑為默認(rèn)路徑,如果不在此處,自己找一下 find / -name "nginx.conf"

         

        location / {
           root html;
           #添加以下配置
           image on;
           image_output on;
        }
        或者指定目錄開啟


        location /upload {
           root html; 
           image on;
           image_output on;
        }

         

        其他參數(shù)說明:


        image on/off 是否開啟縮略圖功能,默認(rèn)關(guān)閉
        image_backend on/off 是否開啟鏡像服務(wù),當(dāng)開啟該功能時,請求目錄不存在的圖片(判斷原圖),將自動從鏡像服務(wù)器地址下載原圖
        image_backend_server 鏡像服務(wù)器地址
        image_output on/off 是否不生成圖片而直接處理后輸出 默認(rèn)off
        image_jpeg_quality 75 生成JPEG圖片的質(zhì)量 默認(rèn)值75
        image_water on/off 是否開啟水印功能
        image_water_type 0/1 水印類型 0:圖片水印 1:文字水印
        image_water_min 300 300 圖片寬度 300 高度 300 的情況才添加水印
        image_water_pos 0-9 水印位置 默認(rèn)值9 0為隨機位置,1為頂端居左,2為頂端居中,3為頂端居右,4為中部居左,5為中部居中,6為中部居右,7為底端居左,8為底端居中,9為底端居右
        image_water_file 水印文件(jpg/png/gif),絕對路徑或者相對路徑的水印圖片
        image_water_transparent 水印透明度,默認(rèn)20
        image_water_text 水印文字 "Power By Vampire"
        image_water_font_size 水印大小 默認(rèn) 5
        image_water_font 文字水印字體文件路徑
        image_water_color 水印文字顏色,默認(rèn) #000000

         

         調(diào)用說明 



        這里假設(shè)你的nginx 訪問地址為 http://127.0.0.1/
        并在nginx網(wǎng)站根目錄存在一個 test.jpg 的圖片
        通過訪問
        http://127.0.0.1/test.jpg!c300x200.jpg 將會 生成/輸出 test.jpg 300x200 的縮略圖
        其中 c 是生成圖片縮略圖的參數(shù), 300 是生成縮略圖的 寬度 200 是生成縮略圖的 高度
        一共可以生成四種不同類型的縮略圖。
        支持 jpeg / png / gif (Gif生成后變成靜態(tài)圖片)
        C 參數(shù)按請求寬高比例從圖片高度 10% 處開始截取圖片,然后縮放/放大到指定尺寸( 圖片縮略圖大小等于請求的寬高 )
        M 參數(shù)按請求寬高比例居中截圖圖片,然后縮放/放大到指定尺寸( 圖片縮略圖大小等于請求的寬高 )
        T 參數(shù)按請求寬高比例按比例縮放/放大到指定尺寸( 圖片縮略圖大小可能小于請求的寬高 )
        W 參數(shù)按請求寬高比例縮放/放大到指定尺寸,空白處填充白色背景顏色( 圖片縮略圖大小等于請求的寬高 )


        調(diào)用舉例

        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

        瀏覽 22
        點贊
        評論
        收藏
        分享

        手機掃一掃分享

        編輯 分享
        舉報
        評論
        圖片
        表情
        推薦
        點贊
        評論
        收藏
        分享

        手機掃一掃分享

        編輯 分享
        舉報
        1. <strong id="7actg"></strong>
        2. <table id="7actg"></table>

        3. <address id="7actg"></address>
          <address id="7actg"></address>
          1. <object id="7actg"><tt id="7actg"></tt></object>
            色色色AV | 日本黄色成熟视频 | 女战士被触手怪扒开双腿玩 | 色丁香五月激情 | 成人一区二区三区久久精品嫩草 | 内射在线播放 | 99瑟瑟 | 麻豆视频在线播放 | 少妇高潮喷水视频 | 天天噜天天干 |