This php image and Verification Code Generation Principle code 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.