A php code that generates thumbnails proportionally The image in this article is the image address you want to generate. This is a PHP code that generates thumbnails proportionally. As long as you give you a picture, it can generate a picture of a specified size without deformation ekt
A PHP tutorial to generate thumbnail code proportionally
The image in this article is the image address you want to generate. This is a PHP code that generates thumbnails proportionally. As long as you give you a picture, it can generate a picture of a specified size without deformation ekt
*/
function resizeimage($image,$width,$height,$scale) {
list($imagewidth, $imageheight, $imagetype) = getimagesize($image);
$imagetype = image_type_to_mime_type($imagetype);
$newimagewidth = ceil($width * $scale);
$newimageheight = ceil($height * $scale);
$newimage = imagecreatetruecolor($newimagewidth,$newimageheight);
switch($imagetype) {
case "image/gif":
$source=imagecreatefromgif($image);
Break;
case "image/pjpeg":
case "image/jpeg":
case "image/jpg":
$source=imagecreatefromjpeg($image);
Break;
case "image/png":
case "image/x-png":
$source=imagecreatefrompng($image);
Break;
}
imagecopyresampled($newimage,$source,0,0,0,0,$newimagewidth,$newimageheight,$width,$height);
switch($imagetype) {
case "image/gif":
Imagegif($newimage,$image);
Break;
case "image/pjpeg":
case "image/jpeg":
case "image/jpg":
Imagejpeg($newimage,$image,90);
Break;
case "image/png":
case "image/x-png":
Imagepng($newimage,$image);
Break;
}
chmod($image, 0777);
return $image;
}
?>