This article provides a PHP tutorial Chinese character Verification Code generation program, if you create Chinese characters in the picture, need font file and Imagettftext function, we use the time to search online. You have to generate a random number, which has the Mt_rand function; You also use the session to save the random number, and if you need to turn to utf-8, you need to iconv the function.
Class SimpleImage {
var $image;
var $image _type;
function Load ($filename) {
$image _info = getimagesize ($filename);
$this->image_type = $image _info[2];
if ($this->image_type = = imagetype_jpeg) {
$this->image = Imagecreatefromjpeg ($filename);
} elseif ($this->image_type = = imagetype_gif) {
$this->image = imagecreatefromgif ($filename);
} elseif ($this->image_type = = imagetype_png) {
$this->image = imagecreatefrompng ($filename);
}
}
function Save ($filename, $image _type=imagetype_jpeg, $compression =75, $permissions =null) {
if ($image _type = = imagetype_jpeg) {
Imagejpeg ($this->image, $filename, $compression);
} elseif ($image _type = = imagetype_gif) {
Imagegif ($this->image, $filename);
} elseif ($image _type = = imagetype_png) {
Imagepng ($this->image, $filename);
}
if ($permissions! = null) {
chmod ($filename, $permissions);
}
}
function output ($image _type=imagetype_jpeg) {
if ($image _type = = imagetype_jpeg) {
Imagejpeg ($this->image);
} elseif ($image _type = = imagetype_gif) {
Imagegif ($this->image);
} elseif ($image _type = = imagetype_png) {
Imagepng ($this->image);
}
}
function GetWidth () {
Return Imagesx ($this->image);
}
function GetHeight () {
Return Imagesy ($this->image);
}
function Resizetoheight ($height) {
$ratio = $height/$this->getheight ();
$width = $this->getwidth () * $ratio;
$this->resize ($width, $height);
}
function Resizetowidth ($width) {
$ratio = $width/$this->getwidth ();
$height = $this->getheight () * $ratio;
$this->resize ($width, $height);
}
function scale ($scale) {
$width = $this->getwidth () * $scale/100;
$height = $this->getheight () * $scale/100;
$this->resize ($width, $height);
}
function Resize ($width, $height) {
$new _image = Imagecreatetruecolor ($width, $height);
Imagecopyresampled ($new _image, $this->image, 0, 0, 0, 0, $width, $height, $this->getwidth (), $this->getheight ( ));
$this->image = $new _image;
}
}
$newfile = Upload_dir. " /icons/". MD5 ($_session[' user ']->email).". JPG ";//upload file saved directory
$image = new SimpleImage ();
$image->load ($_files[' icons ' [' tmp_name ']);//temporary file name uploaded
$image->resizetowidth (80); Set width
$image->save ($newfile);
?>
http://www.bkjia.com/PHPjc/633007.html www.bkjia.com true http://www.bkjia.com/PHPjc/633007.html techarticle This article provides a PHP tutorial Chinese character Verification Code generation program, if you create Chinese characters in the picture, need font file and Imagettftext function, we use the time to search online. You ...