2013-12-15 24 views
0

的文件大小我用這如何使用PHP的「複製」,以減少圖像

copy($image, "images/covers/$imagepath.jpeg"); 

但是,這是建立全尺寸的圖像,這將佔用一些空間,也說不定。

我該如何修改這個來創建一個稍低的res圖像並減小文件大小?

+0

你應該使用GD http://www.php.net/manual/en/book.image.php – elibyy

+1

問的問題對於代碼**必須顯示對所解決問題的最小理解**。包括嘗試解決方案,爲什麼他們沒有工作,以及*期望*結果。另請參見:[堆棧溢出問題清單](http://meta.stackexchange.com/questions/156810/stack-overflow-question-checklist) –

回答

1

您可以打開和縮放圖像到所需用和高度:

$imagefile = "/path/to/file/image.jpeg"; 
$resource = imagecreatefromjpeg($imagefile); 
imagescale($resource, $new_width, $new_height); 
// save the resource to desired destination 
// the third argument states the quality of the image, can be changed to reduce filesize 
imagejpeg($resource, "images/covers/$imagepath.jpeg", 80); 
imagedestroy($resource);