php 縮略圖實現(xiàn)函數(shù)代碼
更新時間:2011年06月23日 22:30:11 作者:
php 生成縮略圖函數(shù)非常簡單,只是調(diào)入了幾個GD的系統(tǒng)函數(shù),不過卻很實用
array getimagesize ( string $filename [, array &$imageinfo ] ) 取得圖像大小
resource imagecreatetruecolor ( int $x_size , int $y_size ) 新建一個真彩色圖像
resource imagecreatefromjpeg ( string $filename ) 從 JPEG 文件或 URL 新建一圖像
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 ) 拷貝部分圖像并調(diào)整大小
bool imagejpeg ( resource $image [, string $filename [, int $quality ]] ) 以 JPEG 格式將圖像輸出到瀏覽器或文件
<?php
/*
Created by <A >http://www.cnphp.info</A>
*/
// 文件及縮放尺寸
//$imgfile = 'smp.jpg';
//$percent = 0.2;
header('Content-type: image/jpeg');
list($width, $height) = getimagesize($imgfile);
$newwidth = $width * $percent;
$newheight = $height * $percent;
$thumb = ImageCreateTrueColor($newwidth,$newheight);
$source = imagecreatefromjpeg($imgfile);
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagejpeg($thumb);
?>
resource imagecreatetruecolor ( int $x_size , int $y_size ) 新建一個真彩色圖像
resource imagecreatefromjpeg ( string $filename ) 從 JPEG 文件或 URL 新建一圖像
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 ) 拷貝部分圖像并調(diào)整大小
bool imagejpeg ( resource $image [, string $filename [, int $quality ]] ) 以 JPEG 格式將圖像輸出到瀏覽器或文件
復(fù)制代碼 代碼如下:
<?php
/*
Created by <A >http://www.cnphp.info</A>
*/
// 文件及縮放尺寸
//$imgfile = 'smp.jpg';
//$percent = 0.2;
header('Content-type: image/jpeg');
list($width, $height) = getimagesize($imgfile);
$newwidth = $width * $percent;
$newheight = $height * $percent;
$thumb = ImageCreateTrueColor($newwidth,$newheight);
$source = imagecreatefromjpeg($imgfile);
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagejpeg($thumb);
?>
您可能感興趣的文章:
- PHP使用imagick讀取PDF生成png縮略圖的兩種方法
- php 根據(jù)url自動生成縮略圖并處理高并發(fā)問題
- php生成縮略圖示例代碼分享(使用gd庫實現(xiàn))
- php利用GD庫生成縮略圖示例
- 使用gd庫實現(xiàn)php服務(wù)端圖片裁剪和生成縮略圖功能分享
- php生成縮略圖填充白邊(等比縮略圖方案)
- PHP imagegrabscreen和imagegrabwindow(截取網(wǎng)站縮略圖)的實例代碼
- 基于PHP服務(wù)端圖片生成縮略圖的方法詳解
- php圖片的裁剪與縮放生成符合需求的縮略圖
- PHPThumb PHP 圖片縮略圖庫
- PHP縮略圖等比例無損壓縮,可填充空白區(qū)域補充色
- PHP用GD庫生成高質(zhì)量的縮略圖片
- 兼容性最強的PHP生成縮略圖的函數(shù)代碼(修改版)
- 兼容性比較好的PHP生成縮略圖的代碼
- 完美實現(xiàn)GIF動畫縮略圖的php代碼
- php下嘗試使用GraphicsMagick的縮略圖功能
- php圖片處理:加水印、縮略圖的實現(xiàn)(自定義函數(shù):watermark、thumbnail)
- php實現(xiàn)上傳圖片生成縮略圖示例
相關(guān)文章
php radio 單選框獲取與保持值的實現(xiàn)代碼
php中讀取單選框radio值的與在php中保持單選按鈕的值的方法,其實都是一樣的原理。2010-05-05apache+mysql+php+ssl服務(wù)器之完全安裝攻略
apache+mysql+php+ssl服務(wù)器之完全安裝攻略...2006-09-09