2014-12-10 80 views
0

我在一個cordova項目。我在服務器端使用Jquery和Jcrop插件和Php gd。 當我上傳用戶的頭像我試圖裁剪圖片。 上傳進行順利,但沒有任何反應。Php上傳文件然後剪裁

PHP代碼:

if(move_uploaded_file($file,$dirname."/avatar.jpeg")){ 
     $targ_w = $targ_h = 150; 
     $src = $dirname.'/avatar.jpeg'; 
     $img_r = imagecreatefromjpeg($src); 
     $dst_r = ImageCreateTrueColor($targ_w, $targ_h); 
     imagecopyresampled($dst_r,$img_r,0,0,$_POST['avatar_x'],$_POST['avatar_y'], $targ_w,$targ_h,$_POST['avatar_w'],$_POST['avatar_h']); 
    }else{...} 

我沒有錯誤消息

+0

您沒有錯誤訊息?你有沒有啓用錯誤檢查? – 2014-12-10 21:25:11

+0

您應該在'imagecopyresampled'後保存圖像。 – putvande 2014-12-10 21:25:42

+0

錯誤檢查已啓用 – Malakiof 2014-12-10 21:26:43

回答

2

什麼也沒有發生,因爲你不這樣做,結果什麼。見the documentation for imagecopyresampled

imagecopyresampled()將採取矩形區域從src_image [...],並將其放置在dst_image一個矩形區域。

運行此功能後,結果將在$dst_r,它仍然是一個內存中的圖像資源。您現在必須將其保存到文件中。這可以用imagejpeg function完成,例如:

imagejpeg($dst_r, "$dirname/avatar_cropped.jpeg");