php影像處理函數imagecopyresampled用法詳解

來源:互聯網
上載者:User
本文執行個體講述了php影像處理函數imagecopyresampled用法。分享給大家供大家參考,具體如下:

文法

bool imagecopyresampled ( 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 )

參數

成功時返回 TRUE, 或者在失敗時返回 FALSE。

案例

案例(映像裁減):

<?php  $targ_w = $targ_h = 150; // 設定目標寬度與高度  $jpeg_quality = 90; // 圖片品質90,滿分為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']); // 靶心圖表 源圖 目標X座標點 目標Y座標點 源的X座標點 源的Y座標點 目標寬度 目標高度 源圖寬度 源圖高度  header('Content-type: image/jpeg');  imagejpeg($dst_r,null,$jpeg_quality); // 輸出圖象到瀏覽器或檔案?>

案例二(重新取樣):

<?php// 源檔案$filename = '1.jpg';// 設定最大寬高$width = 400;$height = 400;// Content typeheader('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);?>

附上上傳圖片的三種思路

1.選擇圖片,提交表單,伺服器統一處理上傳,儲存路徑

2.選擇圖片,上傳,擷取路徑,提交表單,儲存路徑

3.選擇圖片,上傳到伺服器,通過某種途徑擷取到伺服器的圖片,儲存到本地

希望本文所述對大家PHP程式設計有所協助。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.