Php large graph generation code (thumbnail program) _ PHP Tutorial

Source: Internet
Author: User
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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.