Smart PHP image shrinking function: generate various types of thumbnail class names: CreatMiniature basic parameters: $ srcFile, $ echoType * author: beluckly)
* Completion Time: 2006-12-18
* Class name: CreatMiniature
* Function: generate various types of thumbnails.
* Basic parameters: $ srcFile, $ echoType
* Parameters used by the method:
$ ToFile: the generated file.
$ ToW: the generated width.
$ ToH, the generated height
$ Bk1. The highest background color parameter is 255.
$ Bk2, background color parameter
$ Bk3, background color parameter
* Example:
<? Php
/***************************************
* Author: beluckly)
* Completion Time: 2006-12-18
* Class name: CreatMiniature
* Function: generate various types of thumbnails.
* Basic parameters: $ srcFile, $ echoType
* Parameters used by the method:
$ ToFile: the generated file.
$ ToW: the generated width.
$ ToH, the generated height
$ Bk1. The highest background color parameter is 255.
$ Bk2, background color parameter
$ Bk3, background color parameter
Class CreatMiniature
{
// Public variables
Var $ srcFile = ""; // source image
Var $ echoType; // The type of the output image, link -- not saved as a file; file -- saved as a file
Var $ im = ""; // temporary variable
Var $ srcW = ""; // source image width
Var $ srcH = ""; // original height
// Set variables and initialization
Function SetVar ($ srcFile, $ echoType)
{
$ This-> srcFile = $ srcFile;
$ This-> echoType = $ echoType;
$ Info = "";
$ Data = GetImageSize ($ this-> srcFile, $ info );
Switch ($ data [2])
{
Case 1:
If (! Function_exists ("imagecreatefromgif ")){
Echo "your GD library cannot use images in GIF format. please use Jpeg or PNG format! Return ";
Exit ();
}
$ This-> im = ImageCreateFromGIF ($ this-> srcFile );
Break;
Case 2:
If (! Function_exists ("imagecreatefromjpeg ")){
Echo "your GD library cannot use images in jpeg format. please use images in other formats! Return ";
Exit ();
}
$ This-> im = ImageCreateFromJpeg ($ this-> srcFile );
Break;
Case 3:
$ This-> im = ImageCreateFromPNG ($ this-> srcFile );
Break;
}
$ This-> srcW = ImageSX ($ this-> im );
$ This-> srcH = ImageSY ($ this-> im );
}
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