This PHP tutorial generates pictures and verification code picture generation principle code, is by the PHP GD library to support, if your system can not create a picture on the front of the Gd.dll;
?
$w? $RESIZEWIDTH = $w: $RESIZEWIDTH =400;//to generate the width of the picture
$h? $RESIZEHEIGHT = $h: $RESIZEHEIGHT =400;//to generate the height of the picture
function Resizeimage ($im, $maxwidth, $maxheight, $name) {
$width = Imagesx ($im);
$height = Imagesy ($im);
if ($maxwidth && $width > $maxwidth) | | ($maxheight && $height > $maxheight)) {
if ($maxwidth && $width > $maxwidth) {
$widthratio = $maxwidth/$width;
$RESIZEWIDTH =true;//www.111cn.net
}
if ($maxheight && $height > $maxheight) {
$heightratio = $maxheight/$height;
$RESIZEHEIGHT =true;
}
if ($RESIZEWIDTH && $RESIZEHEIGHT) {
if ($widthratio < $heightratio) {
$ratio = $widthratio;
}else{
$ratio = $heightratio;
}
}elseif ($RESIZEWIDTH) {
$ratio = $widthratio;
}elseif ($RESIZEHEIGHT) {
$ratio = $heightratio;
}
$newwidth = $width * $ratio;
$newheight = $height * $ratio;
if (function_exists ("imagecopyresampled")) {
$newim = Imagecreatetruecolor ($newwidth, $newheight);
Imagecopyresampled ($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
}else{
$newim = imagecreate ($newwidth, $newheight);
imagecopyresized ($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
}
imagejpeg ($newim, $name);
Imagedestroy ($newim);
}else{
imagejpeg ($im, $name);
}
}if ($_files[' uploadfile '] [' size ']) {
if ($_files[' uploadfile '] [' type '] = = "Image/pjpeg") {
$im = imagecreatefromjpeg ($_files[' uploadfile '] [' tmp_name ']);
}elseif ($_files[' uploadfile '] [' type '] = = "Image/x-png") {
$im = imagecreatefrompng ($_files[' uploadfile '] [' tmp_name ']);
}elseif ($_files[' uploadfile '] [' type '] = = "Image/gif") {
$im = imagecreatefromgif ($_files[' uploadfile '] [' tmp_name ']);
}
if ($im) {
if (file_exists (' bbs.jpg ')) {
unlink (' www.111cn.net.jpg ');
}
Resizeimage ($im, $RESIZEWIDTH, $RESIZEHEIGHT, ' bbs.jpg ');
Imagedestroy ($im);
}
}
//$uploadfile = "bbs.jpg";
?>
After creating the picture, remember to empty the memory with Imagedestroy.