Class for generating thumbnails in PHP. Php code? Php *** function: generate thumbnails * author: phpox * Date: ThuMay1709: 57: 05CST2007 * classCreatMiniature {public variable var $ srcFile; source image var $ echoType; php code
/**
* Function: generate a thumbnail.
* Author: phpox
* Date: Thu May 17 09:57:05 CST 2007
*/
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)
{
If (! File_exists ($ srcFile )){
Echo Source image file does not exist !;
Exit ();
}
$ 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 );
}
// Generate a distorted thumbnail
Function Distortion ($ toFile, $ toW, $ toH)
{
$ CImg = $ this-> CreatImage ($ this-> im, $ toW, $ toH, 0, 0, 0, $ this-> srcW, $ this-> srcH );
Return $ this-> EchoImage ($ cImg, $ toFile );
ImageDestroy ($ cImg );
}
// Generate a scaled chart
Function PRorate ($ toFile, $ toW, $ toH)
{
$ ToWH = $ toW/$ toH;
$ SrcWH = $ this-> srcW/$ this-> srcH;
If ($ toWH <= $ srcWH)
{
$ FtoW = $ toW;
$ FtoH = $ ftoW * ($ this-> srcH/$ this-> srcW );
}
Else
{
$ FtoH = $ toH;
$ FtoW = $ ftoH * ($ this-> srcW/$ this-> srcH );
}
If ($ this-> srcW> $ toW | $ this-> srcH> $ toH)
{
$ CImg = $ this-> CreatImage ($ this-> im, $ ftoW, $ ftoH, 0, 0, 0, $ this-> srcW, $ this-> srcH );
Return $ this-> EchoImage ($ cImg, $ toFile );
ImageDestroy ($ cImg );
}
Else
{
$ CImg = $ this-> CreatImage ($ this-> im, $ this-> srcW, $ this-> srcH, 0, 0, 0, $ this-> srcW, $ this-> srcH );
Return $ this-> EchoImage ($ cImg, $ toFile );
ImageDestroy ($ cImg );
}
}
// Generate a thumbnail after minimum cropping
Function Cut ($ toFile, $ toW, $ toH)
{
$ ToWH = $ toW/$ toH;
$ SrcWH = $ this-> srcW/$ this-& g
Why? Php/*** function: generate thumbnails * author: phpox * Date: Thu May 17 09:57:05 CST 2007 */class CreatMiniature {// public variable var $ srcFile = ""; // original image var $ echoType ;/...