Php large Graph Generation small graph code (thumbnail program) This is a use of the php built-in function to generate a specified large graph code of the specified size Oh easy to use, you only need to set the following four parameters to generate a thumbnail of your desired size.
Php tutorial big Graph Generation Code (thumbnail Program)
This is a thumbnail code that uses the function provided by php to generate a specified large image.
Easy to use. You only need to set the following four parameters to generate a thumbnail of your desired size.
*/
Function bigtosmallimg ($ file, $ path, $ w = 120, $ h = 90)
{
$ Img = $ path. $ file;
$ Imgarr = getimagesize ($ img );
$ Sw = $ imgarr [0]; // source Image Width
$ Sh = $ imgarr [1]; // Original Image Height
$ Stype = $ imgarr [2];
// Proportional Scaling
If ($ sw/$ sh> $ w/$ h ){
$ Mw = $ w;
$ Mh = (int) $ sh * ($ w/$ sw );
}
Else {
$ Mw = (int) $ sw * ($ h/$ sh );
$ Mh = $ h;
}
Switch ($ stype) {// create a source file to generate a thumbnail Based on the uploaded image 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, $ 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 a thumbnail of www. bKjia. c0m'. $ stype. ');
Break;
}
Imagedestroy ($ desf );
Imagedestroy ($ srcf );
}
// Call this thumbnail
Bigtosmallimg ($ file, $ path, $ w = 120, $ h = 90 );
/*
$ File = image path
$ Path = path saved after generation
$ W = Image Width
$ H = Image Height
*/