function imageResize($maxWidth, $maxHeight, $fileFrom, $fileTo) { $img = false; if (is_file($fileFrom)) { $img = imagecreatefromstring(file_get_contents($fileFrom)); } if($img) { $width = ImageSX($img); $height = ImageSY($img); $maxWidth = ($maxHeight=='*'?1000000:$maxHeight); $maxHeight = ($maxHeight=='*'?1000000:$maxHeight); if ($width > $maxWidth || $height > $maxHeight) { $ratioX = $width/$maxWidth; $ratioY = $height/$maxHeight; $ratio = ($ratioX > $ratioY)?$ratioX:$ratioY; $newWidth = $width / $ratio; $newHeight = $height / $ratio; $newImage=ImageCreateTrueColor($newWidth, $newHeight); ImageCopyResampled ($newImage, $img, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height); ImageJPEG($newImage, $fileTo, 80); } else { ImageJPEG($img, $fileTo, 80); } return true; } else { return false; } }