php gd等比例縮放壓縮圖片函數(shù)
來源:易賢網(wǎng) 閱讀:1499 次 日期:2016-08-17 15:37:09
溫馨提示:易賢網(wǎng)小編為您整理了“php gd等比例縮放壓縮圖片函數(shù)”,方便廣大網(wǎng)友查閱!

本文實例為大家分享了php gd等比例縮放壓縮圖片函數(shù),供大家參考,具體內容如下

<?php

  /**

   * desription 判斷是否gif動畫

   * @param sting $image_file圖片路徑

   * @return boolean t 是 f 否

   */

  function check_gifcartoon($image_file){

    $fp = fopen($image_file,'rb');

    $image_head = fread($fp,1024);

    fclose($fp);

    return preg_match("/".chr(0x21).chr(0xff).chr(0x0b).'NETSCAPE2.0'."/",$image_head)?false:true;

  }

  /**

  * desription 壓縮圖片

  * @param sting $imgsrc 圖片路徑

  * @param string $imgdst 壓縮后保存路徑

  */

  function compressed_image($imgsrc,$imgdst){

    list($width,$height,$type)=getimagesize($imgsrc);

    $new_width = ($width>600?600:$width)*0.9;

    $new_height =($height>600?600:$height)*0.9;

    switch($type){

      case 1:

        $giftype=check_gifcartoon($imgsrc);

        if($giftype){

          header('Content-Type:image/gif');

          $image_wp=imagecreatetruecolor($new_width, $new_height);

          $image = imagecreatefromgif($imgsrc);

          imagecopyresampled($image_wp, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

          //75代表的是質量、壓縮圖片容量大小

          imagejpeg($image_wp, $imgdst,75);

          imagedestroy($image_wp);

        }

        break;

      case 2:

        header('Content-Type:image/jpeg');

        $image_wp=imagecreatetruecolor($new_width, $new_height);

        $image = imagecreatefromjpeg($imgsrc);

        imagecopyresampled($image_wp, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

        //75代表的是質量、壓縮圖片容量大小

        imagejpeg($image_wp, $imgdst,75);

        imagedestroy($image_wp);

        break;

      case 3:

        header('Content-Type:image/png');

        $image_wp=imagecreatetruecolor($new_width, $new_height);

        $image = imagecreatefrompng($imgsrc);

        imagecopyresampled($image_wp, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

        //75代表的是質量、壓縮圖片容量大小

        imagejpeg($image_wp, $imgdst,75);

        imagedestroy($image_wp);

        break;

    }

  }

php and gd 函數(shù)參考表

gd_info 取得當前安裝的 GD 庫的信息

getimagesize 取得圖像大小

getimagesizefromstring Get the size of an image from a string

image_type_to_extension 取得圖像類型的文件后綴

image_type_to_mime_type 取得 getimagesize,exif_read_data,exif_thumbnail,exif_imagetype 所返回的圖像類型的 MIME 類型

image2wbmp 以 WBMP 格式將圖像輸出到瀏覽器或文件

imageaffine Return an image containing the affine tramsformed src image, using an optional clipping area

imageaffinematrixconcat Concat two matrices (as in doing many ops in one go)

imageaffinematrixget Return an image containing the affine tramsformed src image, using an optional clipping area

imagealphablending 設定圖像的混色模式

imageantialias 是否使用抗鋸齒(antialias)功能

imagearc 畫橢圓弧

imagechar 水平地畫一個字符

imagecharup 垂直地畫一個字符

imagecolorallocate 為一幅圖像分配顏色

imagecolorallocatealpha 為一幅圖像分配顏色 + alpha

imagecolorat 取得某像素的顏色索引值

imagecolorclosest 取得與指定的顏色最接近的顏色的索引值

imagecolorclosestalpha 取得與指定的顏色加透明度最接近的顏色

imagecolorclosesthwb 取得與給定顏色最接近的色度的黑白色的索引

imagecolordeallocate 取消圖像顏色的分配

imagecolorexact 取得指定顏色的索引值

imagecolorexactalpha 取得指定的顏色加透明度的索引值

imagecolormatch 使一個圖像中調色板版本的顏色與真彩色版本更能匹配

imagecolorresolve 取得指定顏色的索引值或有可能得到的最接近的替代值

imagecolorresolvealpha 取得指定顏色 + alpha 的索引值或有可能得到的最接近的替代值

imagecolorset 給指定調色板索引設定顏色

imagecolorsforindex 取得某索引的顏色

imagecolorstotal 取得一幅圖像的調色板中顏色的數(shù)目

imagecolortransparent 將某個顏色定義為透明色

imageconvolution 用系數(shù) div 和 offset 申請一個 3x3 的卷積矩陣

imagecopy 拷貝圖像的一部分

imagecopymerge 拷貝并合并圖像的一部分

imagecopymergegray 用灰度拷貝并合并圖像的一部分

imagecopyresampled 重采樣拷貝部分圖像并調整大小

imagecopyresized 拷貝部分圖像并調整大小

imagecreate 新建一個基于調色板的圖像

imagecreatefromgd2 從 GD2 文件或 URL 新建一圖像

imagecreatefromgd2part 從給定的 GD2 文件或 URL 中的部分新建一圖像

imagecreatefromgd 從 GD 文件或 URL 新建一圖像

imagecreatefromgif 由文件或 URL 創(chuàng)建一個新圖象。

imagecreatefromjpeg 由文件或 URL 創(chuàng)建一個新圖象。

imagecreatefrompng 由文件或 URL 創(chuàng)建一個新圖象。

imagecreatefromstring 從字符串中的圖像流新建一圖像

imagecreatefromwbmp 由文件或 URL 創(chuàng)建一個新圖象。

imagecreatefromwebp 由文件或 URL 創(chuàng)建一個新圖象。

imagecreatefromxbm 由文件或 URL 創(chuàng)建一個新圖象。

imagecreatefromxpm 由文件或 URL 創(chuàng)建一個新圖象。

imagecreatetruecolor 新建一個真彩色圖像

imagecrop Crop an image using the given coordinates and size, x, y, width and height

imagecropauto Crop an image automatically using one of the available modes

imagedashedline 畫一虛線

imagedestroy 銷毀一圖像

imageellipse 畫一個橢圓

imagefill 區(qū)域填充

imagefilledarc 畫一橢圓弧且填充

imagefilledellipse 畫一橢圓并填充

imagefilledpolygon 畫一多邊形并填充

imagefilledrectangle 畫一矩形并填充

imagefilltoborder 區(qū)域填充到指定顏色的邊界為止

imagefilter 對圖像使用過濾器

imageflip Flips an image using a given mode

imagefontheight 取得字體高度

imagefontwidth 取得字體寬度

imageftbbox 給出一個使用 FreeType 2 字體的文本框

imagefttext 使用 FreeType 2 字體將文本寫入圖像

imagegammacorrect 對 GD 圖像應用 gamma 修正

imagegd2 將 GD2 圖像輸出到瀏覽器或文件

imagegd 將 GD 圖像輸出到瀏覽器或文件

imagegif 輸出圖象到瀏覽器或文件。

imagegrabscreen Captures the whole screen

imagegrabwindow Captures a window

imageinterlace 激活或禁止隔行掃描

imageistruecolor 檢查圖像是否為真彩色圖像

imagejpeg 輸出圖象到瀏覽器或文件。

imagelayereffect 設定 alpha 混色標志以使用綁定的 libgd 分層效果

imageline 畫一條線段

imageloadfont 載入一新字體

imagepalettecopy 將調色板從一幅圖像拷貝到另一幅

imagepalettetotruecolor Converts a palette based image to true color

imagepng 以 PNG 格式將圖像輸出到瀏覽器或文件

imagepolygon 畫一個多邊形

imagepsbbox 給出一個使用 PostScript Type1 字體的文本方框

imagepsencodefont 改變字體中的字符編碼矢量

imagepsextendfont 擴充或精簡字體

imagepsfreefont 釋放一個 PostScript Type 1 字體所占用的內存

imagepsloadfont 從文件中加載一個 PostScript Type 1 字體

imagepsslantfont 傾斜某字體

imagepstext 用 PostScript Type1 字體把文本字符串畫在圖像上

imagerectangle 畫一個矩形

imagerotate 用給定角度旋轉圖像

imagesavealpha 設置標記以在保存 PNG 圖像時保存完整的 alpha 通道信息(與單一透明色相反)

imagescale Scale an image using the given new width and height

imagesetbrush 設定畫線用的畫筆圖像

imagesetinterpolation Set the interpolation method

imagesetpixel 畫一個單一像素

imagesetstyle 設定畫線的風格

imagesetthickness 設定畫線的寬度

imagesettile 設定用于填充的貼圖

imagestring 水平地畫一行字符串

imagestringup 垂直地畫一行字符串

imagesx 取得圖像寬度

imagesy 取得圖像高度

imagetruecolortopalette 將真彩色圖像轉換為調色板圖像

imagettfbbox 取得使用 TrueType 字體的文本的范圍

imagettftext 用 TrueType 字體向圖像寫入文本

imagetypes 返回當前 PHP 版本所支持的圖像類型

imagewbmp 以 WBMP 格式將圖像輸出到瀏覽器或文件

imagewebp Output an WebP image to browser or file

imagexbm 將 XBM 圖像輸出到瀏覽器或文件

iptcembed 將二進制 IPTC 數(shù)據(jù)嵌入到一幅 JPEG 圖像中

iptcparse 將二進制 IPTC 塊解析為單個標記

jpeg2wbmp 將 JPEG 圖像文件轉換為 WBMP 圖像文件

png2wbmp 將 PNG 圖像文件轉換為 WBMP 圖像文件

以上就是本文的全部內容,希望對大家學習PHP程序設計有所幫助。

更多信息請查看網(wǎng)絡編程
易賢網(wǎng)手機網(wǎng)站地址:php gd等比例縮放壓縮圖片函數(shù)

2025國考·省考課程試聽報名

  • 報班類型
  • 姓名
  • 手機號
  • 驗證碼
關于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點 | 投訴建議
工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務許可證:(云)人服證字(2023)第0102001523號
聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關注公眾號:hfpxwx
咨詢QQ:1093837350(9:00—18:00)版權所有:易賢網(wǎng)