《PHP學(xué)習(xí):php圖像處理函數(shù)imagecopyresampled用法詳解》要點(diǎn):
本文介紹了PHP學(xué)習(xí):php圖像處理函數(shù)imagecopyresampled用法詳解,希望對(duì)您有用。如果有疑問(wèn),可以聯(lián)系我們。
本文實(shí)例講述了php圖像處理函數(shù)imagecopyresampled用法.分享給大家供大家參考,具體如下:PHP編程
語(yǔ)法
PHP編程
參數(shù)PHP編程
dst_image | 目標(biāo)圖象連接資源. |
src_image | 源圖象連接資源. |
dst_x | 目標(biāo) X 坐標(biāo)點(diǎn). |
dst_y | 目標(biāo) Y 坐標(biāo)點(diǎn). |
src_x | 源的 X 坐標(biāo)點(diǎn). |
src_y | 源的 Y 坐標(biāo)點(diǎn). |
dst_w | 目標(biāo)寬度. |
dst_h | 目標(biāo)高度. |
src_w | 源圖象的寬度. |
src_h | 源圖象的高度. |
成功時(shí)返回 TRUE, 或者在失敗時(shí)返回 FALSE.PHP編程
案例PHP編程
案例(圖像裁減):PHP編程
<?php $targ_w = $targ_h = 150; // 設(shè)置目標(biāo)寬度與高度 $jpeg_quality = 90; // 圖片質(zhì)量90,滿(mǎn)分為100 $src = 'demo_files/pool.jpg'; // 被處理的圖片 $img_r = imagecreatefromjpeg($src); // 獲取原圖 $dst_r = ImageCreateTrueColor( $targ_w, $targ_h ); // 獲取新圖 imagecopyresampled($dst_r,$img_r,0,0,$_POST['x'],$_POST['y'], $targ_w,$targ_h,$_POST['w'],$_POST['h']); // 目標(biāo)圖 源圖 目標(biāo)X坐標(biāo)點(diǎn) 目標(biāo)Y坐標(biāo)點(diǎn) 源的X坐標(biāo)點(diǎn) 源的Y坐標(biāo)點(diǎn) 目標(biāo)寬度 目標(biāo)高度 源圖寬度 源圖高度 header('Content-type: image/jpeg'); imagejpeg($dst_r,null,$jpeg_quality); // 輸出圖象到瀏覽器或文件 ?>
案例二(重新取樣):PHP編程
<?php // 源文件 $filename = '1.jpg'; // 設(shè)置最大寬高 $width = 400; $height = 400; // Content type header('Content-Type: image/jpeg'); // 獲取新尺寸 list($width_orig, $height_orig) = getimagesize($filename); $ratio_orig = $width_orig/$height_orig; if ($width/$height > $ratio_orig) { $width = $height*$ratio_orig; } else { $height = $width/$ratio_orig; } // 重新取樣 $image_p = imagecreatetruecolor($width, $height); $image = imagecreatefromjpeg($filename); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); // 輸出 imagejpeg($image_p, null, 100); ?>
附上上傳圖片的三種思路PHP編程
1.選擇圖片,提交表單,服務(wù)器統(tǒng)一處理上傳,保存路徑PHP編程
2.選擇圖片,上傳,獲取路徑,提交表單,保存路徑PHP編程
3.選擇圖片,上傳到服務(wù)器,通過(guò)某種途徑獲取到服務(wù)器的圖片,保存到本地PHP編程
更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專(zhuān)題:《PHP圖形與圖片操作技巧匯總》、《PHP基本語(yǔ)法入門(mén)教程》、《PHP運(yùn)算與運(yùn)算符用法總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門(mén)教程》、《PHP網(wǎng)絡(luò)編程技巧總結(jié)》、《PHP數(shù)組(Array)操作技巧大全》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫(kù)操作入門(mén)教程》及《php常見(jiàn)數(shù)據(jù)庫(kù)操作技巧匯總》PHP編程
希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助.PHP編程
轉(zhuǎn)載請(qǐng)注明本頁(yè)網(wǎng)址:
http://www.fzlkiss.com/jiaocheng/2519.html