• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

一个关于php里面GP库的有关问题

php 搞代码 4年前 (2022-01-24) 14次浏览 已收录 0个评论

求助一个关于php里面GP库的问题
把GD库封装进类里面了,但不知道在那里出错了,
请有空滴大牛们帮忙看看,小弟感激不尽,谢谢
找了两天都没找到那里错了,图片还是显示不了,
如:

(先写了个表单biaodan.php)

codetest
<meta charset=”utf-8 “>
<style type=”text/css”></style>

<body>

name:

pass:

code:

(然后封装了个类vcode.class.php)
<?php
class Vcode{
private $width; //宽
private $height;//高
private $num; //数量
private $code;//验证码
private $img; //图像的资源

//构造方法, 三个参数
function __construct($width,$height,$num){
$this->width=$width;
$this->height=$height;
$this->num=$num;
$this->code=$this->gocode();//调用自己的方法
}

//获取字符的验证码, 用于保存在服务器中
function getcode(){

return $this->code;

}
//输出图像
function outimg(){
//创建背景 (颜色, 大小, 边框)
$this->createback();

//输出图像
$this->printimg();
}
//创建背景
private function createback(){
//创建资源
$this->img=imagecreatetruecolor($this->width,$htis->height);
//设置随机颜色
$bgcolor=imagecolorallocate($this->img,rand(225,255),rand(225,255),rand(225,255));
//设置背景填充
imagefill($this->img,0,0,$bgcolor);
//画边框
$bordercolor=imagecolorallocate($this->img,0,0,0);
imagerectangle($this->img,0,0,$this->width-1,$this->height-1,$bordercolor);
}

//画字
private function outstring(){

}

//设置干扰元素
private function grcode(){

}

//输出图像
private function printimg(){
if(imagetypes() & IMG_GIF){
header(“Content-type:image/gif”);
imagegif($this->img);
}else if(imagetypes() & IMG_JPG){
header(“Content-type:image/jpeg”);
imagejpeg($this->img);
}else if(imagetypes() & IMG_PNG){
header(“Content-type:image/png”);
imagepng($this->img);
}else{
die(“No image support in this PHP server”);
}
}

。本文来源gao!%daima.com搞$代*!码网1

搞代gaodaima码
//生成验证码字符串
private function gocode(){
$codes = “3456789abcdefghijkmnpqrstuvwxyABCDEFGHIJKLMNPQRSTUVWXY”;
$code= “”;
for($i=0;$inum;$i++){
$code.=$codes{rand(0,strlen($codes)-1)};
}
return $code;
}

//用于自动销毁图像资源
function __destruct(){
imagedestroy($this->img);
}

}

(在调用类code.php)
<?php
//开启session
session_start();
include “vcode.class.php”;
//构造方法
$vcode= new Vcode(80,25,4);
//将验证码放到服务器自己的空间保存一份
$_SESSION=$vcode->getcode();
//将验证码图片输出
$vcode->outimg();
——解决思路———————-
//创建资源
$this->img=imagecreatetruecolor($this->width,$htis->height);


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:一个关于php里面GP库的有关问题

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址