function resizeImage($sourceImage, $thumbImage, $thumbWidth)
{
$srcImg = imagecreatefromjpeg($sourceImage);
$origWidth = imagesx($srcImg);
$origHeight = imagesy($srcImg);
if($origWidth > $thumbWidth){
$ratio = $origWidth / $thumbWidth;
$thumbHeight = floor($origHeight / $ratio);
$thumbImg = imagecreatetruecolor($thumbWidth, $thumbHeight);
imagecopyresized($thumbImg, $srcImg, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $origWidth, $origHeight);
imagejpeg($thumbImg, $thumbImage);
}else{
$thumbWidth = $origWidth;
$ratio = $origWidth / $thumbWidth;
$thumbHeight = floor($origHeight / $ratio);
$thumbImg = imagecreatetruecolor($thumbWidth, $thumbHeight);
imagecopyresized($thumbImg, $srcImg, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $origWidth, $origHeight);
imagejpeg($thumbImg, $thumbImage);
}
}
Sign up here with your email