This PHP generated image and verification code image generation principle code, is supported by the PHP GD library, if your system can not create pictures on the front of the Gd.dll, go again, restart Apache, if IIS restart IIS is OK.
This PHP tutorial generated image and Captcha image generation principle code, is supported by the PHP GD library, if your system can not create pictures on the front of the Gd.dll, go again, restart Apache, if IIS restart IIS is OK.
$w? $RESIZEWIDTH = $w: $RESIZEWIDTH =400;//The width of the resulting picture
$h? $RESIZEHEIGHT = $h: $RESIZEHEIGHT =400;//The height of the generated 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.bkjia.c0m
}
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.bKjia.c0m.jpg ');
}
Resizeimage ($im, $RESIZEWIDTH, $RESIZEHEIGHT, ' bbs.jpg ');
Imagedestroy ($im);
}
}
$uploadfile = "Bbs.jpg";
?>
After creating the picture , remember to empty the memory with Imagedestroy.
http://www.bkjia.com/PHPjc/633049.html www.bkjia.com true http://www.bkjia.com/PHPjc/633049.html techarticle this PHP generated image and verification code image generation principle code, is supported by the PHP GD library, if your system can not create pictures on the front of the Gd.dll; Go again, re-start Apache, if IIS re-start ...