PHP code
/**
* Function: Generate thumbnail image
* Author: phpox
* Date: Thu 09:57:05 CST 2007
*/
Class Creatminiature
{
Public variables
var $srcFile = ""; Original
var $echoType; Output picture type, link--not saved as file; file--saved as File
var $im = ""; Temp variable
var $srcW = ""; Original width
var $srcH = ""; Original height
Setting variables and initialization
function SetVar ($srcFile, $echoType)
{
if (!file_exists ($srcFile)) {
echo Source picture 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 GIF format pictures, please use JPEG or PNG format!" Return ";
Exit ();
}
$this->im = imagecreatefromgif ($this->srcfile);
Break
Case 2:
if (!function_exists ("Imagecreatefromjpeg")) {
echo "Your GD library can not use JPEG format pictures, please use other format pictures!" 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);
}
To create a distorted shape thumbnail
function Distortion ($toFile, $toW, $toH)
{
$CIMG = $this->creatimage ($this->im, $toW, $toH, 0,0,0,0, $this->SRCW, $this->srch);
return $this->echoimage ($CIMG, $toFile);
Imagedestroy ($CIMG);
}
To generate a proportionally scaled thumbnail
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,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,0, $this->SRCW, $this->srch);
return $this->echoimage ($CIMG, $toFile);
Imagedestroy ($CIMG);
}
}
Generate the smallest cropped thumbnail
function Cut ($toFile, $toW, $toH)
{
$toWH = $toW/$toH;
$srcWH = $this->srcw/$this-&g
http://www.bkjia.com/PHPjc/478786.html www.bkjia.com true http://www.bkjia.com/PHPjc/478786.html techarticle PHP code? PHP/** * function: Generate thumbnails * Author: phpox * Date: Thu may 09:57:05 CST */class Creatminiature {//public variable var $srcFile = " "; Original Var $echoType; /...