To use PHP to generate thumbnail images, make sure your PHP server has a GD2 graphics library that uses a class to generate thumbnail images of the pictures
1. How to use
$resizeimage = new Resizeimage ("Picture source file Address", "200", "100", "0", "thumbnail address");
Just use the words above, you can generate thumbnails, where the source file and thumbnail address can be the same, 200,100 representing width and height
2. Thumbnail Class Code
Use the following class to generate picture thumbnails, <?php class Resizeimage {//Picture type var $type;
Actual width var $width;
The actual height of Var $height;
Change the width of var $resize _width;
After changing the height of var $resize _height;
Whether to map Var $cut;
source image var $srcimg;
Target image address Var $dstimg;
A temporarily created image Var $im;
function Resizeimage ($img, $wid, $hei, $c, $dstpath) {$this->srcimg = $img;
$this->resize_width = $wid;
$this->resize_height = $hei;
$this->cut = $c;
Type of picture $this->type = Strtolower (substr (STRRCHR ($this->srcimg, "."), 1));
Initialization of Image $this->initi_img ();
The target image address $this-> dst_img ($dstpath);
--$this->width = Imagesx ($this->im);
$this->height = Imagesy ($this->im);
Generating Image $this->newimg ();
Imagedestroy ($this->im);
function newimg () {//The proportions of the altered image $resize _ratio = ($this->resize_width)/($this->resize_height);
The proportions of the actual image $ratio = ($this->width)/($this->height); if ($this->cut = = "1")//Map {if ($ratio >= $resize _ratio)//high priority {$newimg = Imagecreatetruecolor
($this->resize_width, $this->resize_height); Imagecopyresampled ($newimg, $this->im, 0, 0, 0, 0, $this->resize_width, $this->resize_height, ($this->
Height) * $resize _ratio), $this->height);
Imagejpeg ($newimg, $this->dstimg); } if ($ratio < $resize _ratio)//width First {$newimg = Imagecreatetruecolor ($this->resize_width, $th
Is->resize_height); Imagecopyresampled ($newimg, $this->im, 0, 0, 0, 0, $this->resize_width, $this->resize_height, $this->width
, (($this->width)/$resize _ratio));
Imagejpeg ($newimg, $this->dstimg); } else//do not map {if ($ratio >= $resize _ratio) {$newimg = Imagecreatetruecolor ($this-&
Gt;resize_width, ($this->resize_width)/$ratio); Imagecopyresampled ($newimg, $this->im, 0, 0, 0, 0, $this->resize_width, ($this->resize_width)/$ratio, $this->width, $this->height);
Imagejpeg ($newimg, $this->dstimg); } if ($ratio < $resize _ratio) {$newimg = Imagecreatetruecolor ($this->resize_height) * $ratio, $this-
>resize_height); Imagecopyresampled ($newimg, $this->im, 0, 0, 0, 0, ($this->resize_height) * $ratio, $this->resize_height, $
This->width, $this->height);
Imagejpeg ($newimg, $this->dstimg); }}///Initialize image function Initi_img () {if ($this->type== "jpg") {$this->im = imagecreatefromj
Peg ($this->srcimg);
} if ($this->type== "gif") {$this->im = imagecreatefromgif ($this->srcimg);
} if ($this->type== "png") {$this->im = imagecreatefrompng ($this->srcimg);
}//Image target Address function dst_img ($dstpath) {$full _length = strlen ($this->srcimg);
$type _length = strlen ($this->type); $name _length = $full _length-$type _length;
$name = substr ($this->srcimg,0, $name _length-1);
$this->dstimg = $dstpath;
Echo $this->dstimg;
}}?>