下面的代碼工作沒有任何錯誤,但我的問題是當我創建縮略圖有時縮略圖是不可理解的(一些條件如寬度比高度大)我也試過一個代碼計算高度自動。但它不會完美的作品。我想這將創建一個可以理解的縮略圖每次一碼(可生成裁剪縮略圖)創建完美的縮略圖
function make_thumb($src, $dest, $desired_width)
{
$source_image = imagecreatefromjpeg($src);
$width = imagesx($source_image);
$height = imagesy($source_image);
//even if height is calculated automatically using
$desired_height = floor($height * ($desired_width/$width));
$virtual_image = imagecreatetruecolor($desired_width, $desired_height);
imagecopyresampled($virtual_image, $source_image, 0, 0, 0, 0, $desired_width, $desired_height, $width, $height);
imagejpeg($virtual_image, $dest);
}
代碼
– 2013-03-02 15:54:11