PHP-generated thumbnail class_php tutorial

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

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.