How php generates images and verification code images. This php image generation and verification code is supported by the phpgd Library. if your system cannot create images, use gd. before the dll, restart apache. if it is iis, restart the php image generation and verification code image generation principle code, which is supported by the php gd Library, if your system cannot create an image, set gd. before dll; then, restart apache. if it is iis, restart iis.
ThisHow php creates images and verification code imagesThe code is supported by the php gd Library. if your system cannot create an image, you need to replace the gd. dll file. then, restart apache. if it is iis, restart iis.
$ W? $ RESIZEWIDTH = $ w: $ RESIZEWIDTH = 400; // The width of the generated image.
$ H? $ RESIZEHEIGHT = $ h: $ RESIZEHEIGHT = 400; // The height of the generated image.
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 ";
?>
Create imageRemember to use ImageDestroy to clear the memory.
The gd Library is supported. if your system cannot create images, remove the image before gd. dll. then restart apache. if it is iis, restart it...