list($width,$height,$type) = getImageSize($tempname); $iwidth = 800; if ($iwidth > $width) { $iwidth = $width; } $iheight = round(($iwidth / $width) * $height); $imageres = imagecreatetruecolor($iwidth, $iheight); imagecopyresampled($imageres, $tempres, 0, 0, 0, 0, $iwidth, $iheight, $width, $height); // create the thumbnail $twidth = 100; $theight = 67; $twratio = $twidth / $iwidth; $thratio = $theight / $iheight; if ($twratio >= $thratio) { //work with the height, the width is fine $trwidth = $twidth; if ($twratio != 0) { $trheight = round($twratio * $theight); } else { $trheight = $theight; } $ix = 0; $iy = round(($theight - $trheight) / 2); $tiwidth = $iwidth; $tiheight = $iheight - ($iy * 2); } else { //work with the width, the height is fine if ($thratio != 0) { $trwidth = round($thratio * $twidth); } else { $trwidth = $twidth; } $trheight = $theight; $iy = round(($twidth - $trwidth) / 2); $ix = 0; $tiwidth = $iwidth - ($ix * 2); $tiheight = $iheight; } $thumbres = imagecreatetruecolor($twidth, $theight); imagecopyresampled($thumbres, $tempres, 0, 0, $ix, $iy, $twidth, $theight, $tiwidth, $tiheight);