We have to use the GD library must first open the GD library, specifically as follows
GD Library support for PHP under Windows
Find php.ini, open content, find:
; Extension=php_gd2.dll
Put the front semicolon ";" Remove, then save, if there is no semicolon, that is already open.
The specific reference can be referenced below: http://www.111cn.net/phper/php/48352.htm
One: Add text watermark using method
Require ' image.class.php '
$SRC = "001.jpg";
$content = "Hello";
$font _url= "My.ttf";
$size = 20;
$image =new image ($SRC);
$color =array (
0=>255,
1=>255,
2=>255,
2=>20
);
$local =array (
' X ' =>20,
' Y ' =>30
);
$angle = 10;
$image->fontmark ($content, $font _url, $size, $color, $local, $angle);
$image->show ();
Two: Picture thumbnail use method:
Require ' image.class.php '
$SRC = "001.jpg";
$image =new image ($SRC);
$image->thumb (300,200);
$image->show ();
Three: image.class.php
Class image{
Private $info;
Private $image;
Public Function __contruct ($SRC) {
$info = getimagesize ($SRC);
$this->info=array (
' Width ' => $info [0],
' Height ' => $info [1],
' Type ' =>image_type_to_extension ($info [2],false),
' MIME ' => $info [' MIME '],
);
$fun = "imagecreatefrom{$this->info[' type ']}";
$this->image= $fun ($SRC);
}
Thumbnail image
Public Function THUMD ($width, $height) {
$image _thumb= Imagecreatetruecolor ($width, $height);
Imagecopyresampled ($image _thumb, $this->image,0,0,0,0, $width, $height, $this->info[' width '], $this->info[ ' Height ']);
Imagedestroy ($this->image);
$this->image= $image _thumb;
}
Text watermark
Public Function Fontmark ($content, $font _url, $size, $color, $local, $angle) {
$col =imagecolorallocatealpha ($this->image, $color [0], $color [1], $color [2], $color [3]);
$text =imagettftext ($this->image, $size, $angle, $local [' X '], $local [' Y '], $col, $font _url, $content);
}
Output picture
Public Function Show ()
{
Header ("Content-type:", $this->info[' mime '));
$func = "image{$this->info[' type ']}";
$func ($this->image);
}
Public function Save ($nwename) {
$func = "image{$this->info[' type ']}";
Remove picture display from memory
$func ($this->image);
Save picture
$func ($this->image, $nwename. $this->info[' type ']);
}
Public Function _destruct () {
Imagedestroy ($this->image);
}
}