首页 > 后端开发 > php教程 > php图片验证码跟水印(php100教程33-34-35)

php图片验证码跟水印(php100教程33-34-35)

WBOY
发布: 2016-06-13 11:13:05
原创
746 人浏览过

php图片验证码和水印(php100教程33-34-35)

1.验证码的制作:

che.php

<?php /* *Create on 2013-1-29 *This PHP file is made by ZhengHaibo *blog.csdn.net/nuptboyzhb *///首先要修改php.ini 打开图像处理的库php_gdsession_start();//启动session,用于保存验证码for($i=0;$i<4;$i++){	$rand.=dechex(rand(1,15));}$_SESSION[check_pic]=$rand;//保存验证码$im=imagecreatetruecolor(100, 30);//设置颜色$bg=imagecolorallocate($im, 150, 150, 150);$te=imagecolorallocate($im, 255, 255, 255);//画线条 干扰线条for ($j = 0; $j <5; $j++) {	$te2 = imagecolorallocate($im, rand(0,255),rand(0,255),rand(0,255));	imageline($im,rand(0,100),rand(0,30),rand(0,100),rand(0,30),$te2);}for ($j2 = 0; $j2 < number_variable; $j2++) {	imagesetpixel($im, rand()%100, rand()%30,$te2);}//把字符串写到图像的左上角imagestring($im,6,rand(3,70),rand(0,16),$rand,$te);//输入文字header("Content-type: image/jpeg");imagejpeg($im);?>
登录后复制


index.php

<?php /* *Create on 2013-1-29 *This PHP file is made by ZhengHaibo *blog.csdn.net/nuptboyzhb */session_start();if ($_POST['submit']) {	if ($_POST['check']==$_SESSION[check_pic]) {		echo "验证码输入正确".$_SESSION[check_pic];	}else{		echo "验证码输入错误!";	}}?>
登录后复制
php图片验证码跟水印(php100教程33-34-35)




2.水印的制作

index.php

<?php /* *Create on 2013-1-29 *This PHP file is made by ZhengHaibo *blog.csdn.net/nuptboyzhb *///首先要修改php.ini 打开图像处理的库php_gd$image='nupt.jpg';$img=getimagesize($image);switch ($img[2]){	case 1:		[email&#160;protected]($image);		break;	case 2:		[email&#160;protected]($image);		break;	case 3:		[email&#160;protected]($image);		break;}$waterimg='csdn.jpg';$img2=getimagesize($image);switch ($img2[2]){	case 1:		[email&#160;protected]($waterimg);		break;	case 2:		[email&#160;protected]($waterimg);		break;	case 3:		[email&#160;protected]($waterimg);		break;}$str="http://blog.csdn.net/nuptboyzhb/";$te=imagecolorallocate($im, 255, 255, 255);//把字符串写到图像的左上角imagestring($im,6,rand(3,70),rand(0,16),$str,$te);//把水印图片显示到图像上imagecopy($im, $im2, 0, 30, 0, 0, 40,40);header("Content-type: image/jpeg");imagejpeg($im);?>
登录后复制



相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板