Php large graph generation code (thumbnail program ). 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 php big image to generate the small image code (thumbnail program). This is a method that uses the built-in function of php to generate the thumbnail code of the specified big Image. it is 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
*/
The thumbnail program is used to generate a thumbnail code of the specified size using the function provided by php. it is easy to use, just set it...