帮下小虾米

Jun 13, 2016 am 10:26 AM
color img rand

大虾帮下小虾米。
//使用session_start()
session_start();


//创建随机数
for($i=0;$i $_nmsg .= dechex(mt_rand(1,15));
}

//保存在全局变量session中
$_SESSION['code'] = $_nmsg;

echo $_SESSION['code'];

//长和高
  $_width=75;
$_height=25;

//创建一张图片
$_img = imagecreatetruecolor($_width,$_height);

//创建颜色
$_rn_color = imagecolorallocate($_img, mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));

//填充颜色
imagefill($_img,0,0,$_rn_color);

/* //创建黑色边框
$_black = imagecolorallocate($_img,0,0,0);
imagerectangle($_img,0,0,$_width-1,$_height-1,$_black);
*/
//随机画出6个线条
for($i=0;$i $_rnd_color = imagecolorallocate($_img,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
imageline($_img,mt_rand(0,$_width),mt_rand(0,$_height),mt_rand(0,$_width),mt_rand(0,$_height),$_rnd_color);
}

//随机打雪花
for($i=0;$i $_rnd_color = imagecolorallocate($_img,mt_rand(200,255),mt_rand(200,255),mt_rand(200,255));
imagestring ($_img,1,mt_rand(1,$_width),mt_rand(1,$_height),'*',$_rnd_color);
}

//输出验证码


//输出图像
header("content-Type:image/png");
imagepng($_img);

//销毁函数
imagedestroy($_img);
?>


为什么出来的是乱码???(还有输出验证码环节未写完。)

------解决方案--------------------
要想显示图片程序就只能输出图片内容,绝对不能有其它输出,包括BOM头,报错等等。
你 echo $_SESSION['code']; 扰乱了图片的输出
------解决方案--------------------

PHP code
<?php //使用session_start() session_start();$_nmsg = '';//创建随机数for($i=0;$i<4;$i++){$_nmsg .= dechex(mt_rand(1,15));}//保存在全局变量session中$_SESSION['code'] = $_nmsg;//echo $_SESSION['code'];//长和高  $_width=75;$_height=25;//创建一张图片$_img = imagecreatetruecolor($_width,$_height);//创建颜色//$_rn_color = imagecolorallocate($_img, mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));$_rn_color = imagecolorallocate($_img, 255,255,255);//填充颜色imagefill($_img,0,0,$_rn_color);/* //创建黑色边框$_black = imagecolorallocate($_img,0,0,0);imagerectangle($_img,0,0,$_width-1,$_height-1,$_black);*///随机画出6个线条for($i=0;$i<6;$i++){$_rnd_color = imagecolorallocate($_img,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));imageline($_img,mt_rand(0,$_width),mt_rand(0,$_height),mt_rand(0,$_width),mt_rand(0,$_height),$_rnd_color);}//随机打雪花for($i=0;$i<100;$i++){$_rnd_color = imagecolorallocate($_img,mt_rand(200,255),mt_rand(200,255),mt_rand(200,255));imagestring ($_img,1,mt_rand(1,$_width),mt_rand(1,$_height),'*',$_rnd_color);}//输出验证码//$font = 'arial';$text_color = imagecolorallocate($_img,255,0,0);imagestring($_img,5,20,5,$_nmsg,$text_color);//imagettftext($_img,10,0,10,20,$font,$_nmsg);//输出图像header("content-Type:image/png");imagepng($_img);//销毁函数imagedestroy($_img);?><br><font color="#e78608">------解决方案--------------------</font><br>把最后的环节改一下,然后看看有什么错误信息,以及test.png是否正常<br>
Copy after login
PHP code
//保存图像,不输出// header("content-Type:image/png");imagepng($_img, 'test.png');//销毁函数imagedestroy($_img);<div class="clear">
                 
              
              
        
            </div>
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to open img file How to open img file Sep 18, 2023 am 09:40 AM

Methods to open img files include using virtual optical drive software, using compression software, and using special tools. Detailed introduction: 1. Use virtual optical drive software to open, download and install a virtual optical drive software, right-click the img file, select "Open with" or "Associated Program", select the installed virtual optical drive software in the pop-up dialog box, virtual The optical drive software will automatically load the img file and use it as a disc image in the virtual optical drive. Double-click the disc icon in the virtual optical drive to open the img file and access its contents, etc.

How to solve 'undefined: rand.Seed' error in golang? How to solve 'undefined: rand.Seed' error in golang? Jun 25, 2023 am 08:34 AM

During the development or learning process of using Golang, we may encounter the error message of undefined:rand.Seed. This error usually occurs when you need to use a random number generator, because in Golang you need to set a random number seed before you can use the function in the rand package. This article will explain how to resolve this error. 1. Introduce the math/rand package. First, we need to introduce the math/rand package into the code. exist

How to open img file How to open img file Jul 06, 2023 pm 04:17 PM

How to open the img file: 1. Confirm the img file path; 2. Use the img file opener; 3. Select the opening method; 4. View the picture; 5. Save the picture. The img file is a commonly used image file format, usually used to store picture data.

What is the format of img? What is the format of img? Mar 17, 2023 am 10:33 AM

img is a file compression format, mainly used to create image files of floppy disks. It can be used to compress the contents of an entire floppy disk or an entire CD; files with the extension ".IMG" are created using this file format. ; The img file includes 3 basic nodes, namely "Ehfa_HeaderTag", "Ehfa_File" and "Ehfa_Entry".

How to synchronize random number generation in Golang parallel processing? How to synchronize random number generation in Golang parallel processing? Jun 03, 2024 pm 02:53 PM

Synchronizing random number generation in Go concurrent programming: Use a mutex (sync.Mutex) to control access to the rand.Rand random number generator. Each goroutine acquires the mutex lock before generating random numbers and releases the mutex lock after generating it. This ensures that only one goroutine can access the random number generator at a time, eliminating data races.

How to solve the problem of generating the same random numbers using php rand function How to solve the problem of generating the same random numbers using php rand function Mar 23, 2023 am 09:17 AM

The rand() function uses the same initial seeds on each call. The default initial seed is obtained from the operating system's time, but it only has microsecond accuracy. That is, within a very short period of time, many rand() function calls will use the same initial seed, resulting in the same random number generation. So, how to solve this problem?

U disk pe cannot read img U disk pe cannot read img Mar 19, 2024 pm 12:07 PM

U disk is one of the frequently used storage devices. There will also be some minor problems during use. For example: the U disk cannot be read. How to solve it? Put it away! Can’t read the USB flash drive? 4 steps to teach you how to solve the problem easily. After the USB flash drive has been inserted into the computer, click the Start menu, select Control Panel and put it away! Can’t read the USB flash drive? 4 steps to teach you to easily solve the problem. Find and double-click Device Manager in Control Panel. Keep it! Can’t read the USB flash drive? 4 steps to teach you how to easily solve the problem: Find the Universal Serial Bus controller on the main interface of the Device Manager and put it away! Can’t read the USB flash drive? 4 steps to teach you how to easily find the USB mass storage device, select it, right-click, find Uninstall and put it away! Can’t read the USB flash drive? 4 steps to teach you how to solve the problem easily. Welcome to leave a message for discussion!

what does image tag mean in html what does image tag mean in html Mar 04, 2021 pm 02:37 PM

In HTML, the image tag refers to the tag used to define the image, that is, the "<img>" tag. The img element can embed an image into a web page. The "<img>" tag is used to create a placeholder for the referenced image and link the image to the HTML page; the img tag uses the src attribute to specify the URL for displaying the image. Syntax "<img src="imageurl">".

See all articles