How php generates images and verification code pictures _ PHP Tutorial

Source: Internet
Author: User
Tags imagejpeg
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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.