PHP large image generation code (thumbnail program) This is a code that uses the function that comes with PHP to generate thumbnail images of the specified size from the specified large image. It is easy to use and you only need to set the following four parameters to generate thumbnails of the size you want.
php tutorial large image generation code for small images (thumbnail program)
This is a code that uses the function that comes with PHP to generate thumbnail images of the specified size from the specified large image
It is easy to use and you only need to set the following four parameters to generate thumbnails of the size you want.
*/
function bigtosmallimg($file,$path,$w=120,$h=90)
{
$img=$path.$file;
$imgarr=getimagesize($img);
$sw=$imgarr[0];//Original image width
$sh=$imgarr[1];//Height of original image
$stype=$imgarr[2];
//Scale proportionally
if($sw/$sh>$w/$h){
$mw=$w;
$mh=(int)$sh*($w/$sw);
}
else{
$mw=(int)$sw*($h/$sh);
$mh=$h;
}switch($stype){//Create a new source file for generating thumbnails based on the uploaded graphic file type.
case 1:
$srcf = imagecreatefromgif($img);
Break;
case 2:
$srcf = imagecreatefromjpeg($img);
Break;
case 3:
$srcf = imagecreatefrompng($img);
Break;
default:
Showmsg('Program call error.');
Break;
}$desf =imagecreatetruecolor($mw,$mh);
imagecopyresampled($desf,$srcf,0,0,0,0,$mw,$mh,$sw,$sh);
$sm_name=$path."s_".$file;
switch($stype){
case 1:
Imagegif($desf,$sm_name);
break;
case 2:
Imagejpeg($desf,$sm_name);
break;
case 3:
Imagepng($desf,$sm_name);
break;
default:
Showmsg('Unable to generate thumbnail image of www.bKjia.c0m' . $stype . ');
break;
}
imagedestroy($desf);
imagedestroy($srcf);}
//This thumbnail calling method
bigtosmallimg($file,$path,$w=120,$h=90);
/*
$file = path to the image
$path = path saved after generation
$w =image width
$h =image height
*/