2013-05-03 79 views
0

我不確定這個函數是否執行我打算執行的操作,但我需要的是在文件夾中創建圖像的縮略圖。如何保存PHP圖像處理的輸出

$filename = '../images/' . $new_name; 

header('Content-Type: image/jpeg'); 

list($width, $height) = getimagesize($filename); 

$new_width = $width/$height; 

$new_height = 250/$new_width; 

$new_height = round($new_height); 

$image_p = imagecreatetruecolor(250, $new_height); 
$image_s = imagecreatefromjpeg($filename); 
imagecopyresampled($image_p, $image_s, 0, 0, 0, 0, 250, $new_height, $width, $height); 

imagejpeg($image_p, null, 100); 

所以我需要將最終結果保存到我的文件夾,但不覆蓋原始圖像。我在http://php.net/上找到了這個功能,但我不知道如何保存圖像。

回答

2
imagejpeg($image_p, "path/to/dir/image.jpg", 100); 

而就是這樣。

+0

than a million! =)在圖像加載到服務器時嘗試運行函數時,創建縮略圖時遇到了麻煩,然後決定最好在上傳後運行它。它會影響上傳/處理的速度嗎? – 2013-05-03 00:33:31

+0

當圖像未完全加載到服務器上時,您無法處理它。服務器上的處理在一個實例中進行。唯一的速度分隔符你真的不得不關心它的上傳速度。這裏的因特網連接和文件大小是決定性因素。但是對此你沒有什麼可以做的。 – Daniel 2013-05-03 00:40:57