<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                [TOC] >[success]PHP很強大可以輕松快捷的處理多種數據格式,在圖像處理上也擁有 強大而且簡單的實現方式 PHP處理圖像需要擴展庫GD庫的支持 可以通過PHPINFO()函數查看GD庫是否開啟,如果沒有開啟在 PHP.INI中開啟 檢測擴展庫是否加載: ~~~ extension_loaded("GD") ~~~ ## 圖像處理步驟 1. 發送HTTP頭文件,聲明內容為圖像 2. 創建畫布 3. 創建繪圖所需要的顏色 4. 繪圖(填充畫布、畫圓、畫方塊、畫線條、畫布上寫字) 5. 輸出圖像 6. 釋放圖像資源 ### 發送HTTP頭文件 發送圖像文件給瀏覽器,我們首先需要告訴Web瀏覽器我們輸出的是一 個圖像而不是文本或HTML。這可以通過調用header()函數指定圖像的 MIME類型輸出完成。 ~~~ <?php header("Content-type: image/gif"); header("Content-type: image/gif"); header("Content-type: image/jpeg"); header("Content-type: image/png"); ?> ~~~ ### 創建畫布 ~~~ <?php $src = imageCreateTrueColor(200,100); ?> ~~~ 傳入的兩個參數分別為畫布的寬和高,在繪圖時超出寬高的部分將 不予顯示,且此尺寸即為生成圖片文件時的尺寸。返回值為資源類型。 ### 設置顏色 ~~~ <?php $color = imageColorAllocate($src,255,255,255); ?> ~~~ 顏色從屬于某個圖像資源而存在。顏色實際上是一個整形數值。顏色的后三個參數需傳入值的范圍是0~255,返回布爾值。 ### 填充顏色 ~~~ <?php imageFill($src,0,0,$color); ?> ~~~ ### 繪制空心矩形 ~~~ bool imagerectangle ( resource $image , int $x1 , int $y1 , int $x2 , int $y2 , int $col ) ~~~ imagerectangle() 用 col 顏色在 image 圖像中畫一個矩形,其左上角坐標為 x1, y1,右下角坐標為 x2, y2。圖像的左上角坐標為 0, 0。 ### 繪制實心矩形 ~~~ bool imagefilledrectangle ( resource $image , int $x1 , int $y1 , int $x2 , int $y2 , int $color ) ~~~ imagefilledrectangle() 在 image 圖像中畫一個用 color 顏色填充了的矩形,其左上角坐標為 x1,y1,右下角坐標為 x2,y2。0, 0 是圖像的最左上角。 ### 繪制空心圓形 ~~~ bool imageellipse ( resource $image , int $cx , int $cy , int $width , int $height , int $color ) ~~~ 在指定的坐標上畫一個橢圓。 ### 繪制實心圓 ~~~ bool imagefilledellipse ( resource $image , int $cx , int $cy , int $width , int $height , int $color ) ~~~ 畫一橢圓并填充到指定的 image。 ### 繪制線條 ~~~ bool imageline ( resource $image , int $x1 , int $y1 , int $x2 , int $y2 , int $color ) ~~~ imageline() 用 color 顏色在圖像 image 中從坐標 x1,y1 到 x2,y2(圖像左上角為 0, 0)畫一條線段 ### 繪制單一像素 ~~~ bool imagesetpixel ( resource $image , int $x , int $y , int $color ) ~~~ imagesetpixel() 在 image 圖像中用 color 顏色在 x,y 坐標(圖像左上角為 0,0)上畫一個點。 ### 用特殊字體輸入文本 ~~~ array imagettftext ( resource $image , float $size , float $angle , int $x , int $y , int $color , string $fontfile , string $text ) ~~~ 使用 TrueType 字體將 指定的 text 寫入圖像。 ### 輸出圖像 ~~~ <?php //輸出不同格式的圖像用不同的方法: imagegif(img_resource[,filename]); imagejpeg(img_resource[,filename]); imagepng(img_resource[,filename]); imagebmp(img_resource[,filename]); //第二個可選參數為文件名時,文件被另存同名會覆蓋 ?> ~~~ ### 釋放圖像資源 ~~~ <?php imageDestroy(img_resource) //圖像輸出完畢及時釋放資源,把內存空間留給更需要的程序。 ?> ~~~ ## 操作已有圖像 通過我們需要對圖片進行剪切,加水印,縮放等。 ### 打開外部圖像 ~~~ <?php imageCreateFromgd(filename/url); imageCreateFromgif(filename/url); imageCreateFromjpeg(filename/url); imageCreateFrompng(filename/url); imageCreateFrombmp(filename/url); //返回一個資源類型 ?> ~~~ ### 獲得圖像信息 ~~~ <?php imagesx(img_resource)//取得圖像寬度 imagesy(img_resource)//取得圖像高度 getimagesize(img_file)//取得圖像詳細信息,數組形式 ?> ~~~ ### 拷貝圖像的一部分 ~~~ bool imagecopy ( resource $dst_im , resource $src_im , int $dst_x , int $dst_y , int $src_x , int $src_y , int $src_w , int $src_h ) ~~~ 將 src_im 圖像中坐標從 src_x,src_y 開始,寬度為 src_w,高度為 src_h 的一部分拷貝到 dst_im 圖像中坐標為 dst_x 和 dst_y 的位置上。 ### 拷貝并合并圖像的一部分 ~~~ bool imagecopymerge ( resource $dst_im , resource $src_im , int $dst_x , int $dst_y , int $src_x , int $src_y , int $src_w , int $src_h , int $pct ) ~~~ 將 src_im 圖像中坐標從 src_x,src_y 開始,寬度為 src_w,高度為 src_h 的一部分拷貝到 dst_im 圖像中坐標為 dst_x 和 dst_y 的位置上。兩圖像將根據 pct 來決定合并程度,其值范圍從 0 到 100。當 pct = 0 時,實際上什么也沒做,當為 100 時對于調色板圖像本函數和 imagecopy() 完全一樣,它對真彩色圖像實現了 alpha 透明。 ### 拷貝部分圖像并調整大小 ~~~ bool imagecopyresized ( resource $dst_image , resource $src_image , int $dst_x , int $dst_y , int $src_x , int $src_y , int $dst_w , int $dst_h , int $src_w , int $src_h ) ~~~ imagecopyresized() 將一幅圖像中的一塊矩形區域拷貝到另一個圖像中。dst_image 和 src_image 分別是目標圖像和源圖像的標識符。 >[danger] 練習:創建網站驗證碼類。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看