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

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

<?php

  /**

   * desription 判斷是否gif動(dòng)畫

   * @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代表的是質(zhì)量、壓縮圖片容量大小

          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代表的是質(zhì)量、壓縮圖片容量大小

        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代表的是質(zhì)量、壓縮圖片容量大小

        imagejpeg($image_wp, $imgdst,75);

        imagedestroy($image_wp);

        break;

    }

  }

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

gd_info 取得當(dāng)前安裝的 GD 庫(kù)的信息

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 設(shè)定圖像的混色模式

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

imagearc 畫橢圓弧

imagechar 水平地畫一個(gè)字符

imagecharup 垂直地畫一個(gè)字符

imagecolorallocate 為一幅圖像分配顏色

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

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

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

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

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

imagecolordeallocate 取消圖像顏色的分配

imagecolorexact 取得指定顏色的索引值

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

imagecolormatch 使一個(gè)圖像中調(diào)色板版本的顏色與真彩色版本更能匹配

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

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

imagecolorset 給指定調(diào)色板索引設(shè)定顏色

imagecolorsforindex 取得某索引的顏色

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

imagecolortransparent 將某個(gè)顏色定義為透明色

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

imagecopy 拷貝圖像的一部分

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

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

imagecopyresampled 重采樣拷貝部分圖像并調(diào)整大小

imagecopyresized 拷貝部分圖像并調(diào)整大小

imagecreate 新建一個(gè)基于調(diào)色板的圖像

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

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

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

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

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

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

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

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

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

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

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

imagecreatetruecolor 新建一個(gè)真彩色圖像

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 畫一個(gè)橢圓

imagefill 區(qū)域填充

imagefilledarc 畫一橢圓弧且填充

imagefilledellipse 畫一橢圓并填充

imagefilledpolygon 畫一多邊形并填充

imagefilledrectangle 畫一矩形并填充

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

imagefilter 對(duì)圖像使用過(guò)濾器

imageflip Flips an image using a given mode

imagefontheight 取得字體高度

imagefontwidth 取得字體寬度

imageftbbox 給出一個(gè)使用 FreeType 2 字體的文本框

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

imagegammacorrect 對(duì) GD 圖像應(yīng)用 gamma 修正

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

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

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

imagegrabscreen Captures the whole screen

imagegrabwindow Captures a window

imageinterlace 激活或禁止隔行掃描

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

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

imagelayereffect 設(shè)定 alpha 混色標(biāo)志以使用綁定的 libgd 分層效果

imageline 畫一條線段

imageloadfont 載入一新字體

imagepalettecopy 將調(diào)色板從一幅圖像拷貝到另一幅

imagepalettetotruecolor Converts a palette based image to true color

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

imagepolygon 畫一個(gè)多邊形

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

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

imagepsextendfont 擴(kuò)充或精簡(jiǎn)字體

imagepsfreefont 釋放一個(gè) PostScript Type 1 字體所占用的內(nèi)存

imagepsloadfont 從文件中加載一個(gè) PostScript Type 1 字體

imagepsslantfont 傾斜某字體

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

imagerectangle 畫一個(gè)矩形

imagerotate 用給定角度旋轉(zhuǎn)圖像

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

imagescale Scale an image using the given new width and height

imagesetbrush 設(shè)定畫線用的畫筆圖像

imagesetinterpolation Set the interpolation method

imagesetpixel 畫一個(gè)單一像素

imagesetstyle 設(shè)定畫線的風(fēng)格

imagesetthickness 設(shè)定畫線的寬度

imagesettile 設(shè)定用于填充的貼圖

imagestring 水平地畫一行字符串

imagestringup 垂直地畫一行字符串

imagesx 取得圖像寬度

imagesy 取得圖像高度

imagetruecolortopalette 將真彩色圖像轉(zhuǎn)換為調(diào)色板圖像

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

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

imagetypes 返回當(dāng)前 PHP 版本所支持的圖像類型

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

imagewebp Output an WebP image to browser or file

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

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

iptcparse 將二進(jìn)制 IPTC 塊解析為單個(gè)標(biāo)記

jpeg2wbmp 將 JPEG 圖像文件轉(zhuǎn)換為 WBMP 圖像文件

png2wbmp 將 PNG 圖像文件轉(zhuǎn)換為 WBMP 圖像文件

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家學(xué)習(xí)PHP程序設(shè)計(jì)有所幫助。

更多信息請(qǐng)查看網(wǎng)絡(luò)編程
易賢網(wǎng)手機(jī)網(wǎng)站地址:php gd等比例縮放壓縮圖片函數(shù)
由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢 | 簡(jiǎn)要咨詢須知 | 加入群交流 | 手機(jī)站點(diǎn) | 投訴建議
工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
云南網(wǎng)警備案專用圖標(biāo)
聯(lián)系電話:0871-65317125(9:00—18:00) 獲取招聘考試信息及咨詢關(guān)注公眾號(hào):hfpxwx
咨詢QQ:526150442(9:00—18:00)版權(quán)所有:易賢網(wǎng)
云南網(wǎng)警報(bào)警專用圖標(biāo)