PHP generated image and verification code image generation principle _php Tutorial

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

  • Related Article

    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.