Php large Graph Generation Code (thumbnail Program)

Source: Internet
Author: User

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
*/

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.