2016-06-27 94 views
0

我想裁剪和上傳圖像,我已經嘗試下面的代碼作物圖像。imagecopyresampled不給實際輸出

$img_r = imagecreatefromjpeg('/home/user/site.com/wp-content/themes/my-theme/uploads/test.jpeg'); 

$new_canvas = imagecreatetruecolor(350, 350); 

imagecopyresampled($new_canvas, $img_r, 0, 0, 85, 13, 350, 350, 500, 500); 

imagejpeg($new_canvas, $src); 
imagedestroy($new_canvas); 

我已經上傳圖像500 * 500,並希望裁剪尺寸350 * 350的圖像尺寸頂部X和左Y座標從那裏需要啓動圖像裁剪85px和13像素。

問題是,當它保存到服務器意味着我在服務器上寫同樣的圖像和檢查圖像被裁剪,但不是在該特定區域。

它使圖像變小,並在圖像的左側和右側黑色空間添加。

請讓我知道我做錯了什麼。

在此先感謝。

回答

0

在工作太多後找到答案,這很簡單。

只是改變:

$img_r = imagecreatefromjpeg('/home/user/site.com/wp-content/themes/my-theme/uploads/test.jpeg'); 

TO:

$img_r = imagecreatefromjpeg('site.com/wp-content/themes/my-theme/uploads/test.jpeg'); 

我使用的目錄路徑,應該有URI路徑。