导航:首页 > 编程语言 > phpimagestring乱码

phpimagestring乱码

发布时间:2022-10-04 00:55:11

php生成图片,网页上显示一堆乱码,哪里设置错了,求大神啊!

给你这个代码用吧

我给你改好了

<?php
session_start();

header("content-type:image/png");//设置创建图像的格式

$image_width=70;//设置图像宽度

$image_height=18;//设置图像高度

srand(microtime()*100000);//设置随机数的种子

for($i=0;$i<4;$i++){//循环输出一个4位的随机数

$new_number.=dechex(rand(0,15));

}

$_SESSION['code']=$new_number;//将获取的随机数验证码写入到SESSION变量中


$num_image=imagecreate($image_width,$image_height);//创建一个画布

imagecolorallocate($num_image,255,255,255);//设置画布的颜色

for($i=0;$i<strlen($_SESSION['code']);$i++){//循环读取SESSION变量中的验证码

$font=mt_rand(3,5);//设置随机的字体

$x=mt_rand(1,8)+$image_width*$i/4;//设置随机字符所在位置的X坐标

$y=mt_rand(1,$image_height/4);//设置随机字符所在位置的Y坐标

$color=imagecolorallocate($num_image,mt_rand(0,100),mt_rand(0,150),mt_rand(0,200));//设置字符的颜色

imagestring($num_image,$font,$x,$y,$_SESSION['code'][$i],$color);//水平输出字符

}

imagepng($num_image);//生成PNG格式的图像

imagedestroy($num_image);//释放图像资源
?>

⑵ php在制作图形中用imagestring函数写入的汉字出来的却是乱码怎么改成汉字

需要将汉字转为UTF-8编码。

iconv('GBK','UTF-8','汉字')

⑶ 用php画图时出现乱码,代码哪里需要改的吗

这样写
不要有html代码,而且你最后一个还写错了imagegjpeg($im);,应该是imagejpeg($im);header信息最好在上面
<?php
header('Content-Type: image/jpeg');
$im = imagecreatetruecolor(120, 20);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, 'A Simple Text String', $text_color);
imagejpeg($im);
?>

⑷ 求助!php制作上传图片时候遇到的问题

<?php

/*
* 参数说明
* $max_file_size : 上传文件大小限制, 单位BYTE
* $destination_folder : 上传文件路径
* $watermark : 是否附加水印(1为加水印,其他为不加水印);
*
* 使用说明:
* 1. 将PHP.INI文件里面的"extension=php_gd2.dll"一行前面的;号去掉,因为我们要用到GD库;
* 2. 将extension_dir =改为你的php_gd2.dll所在目录;
*/

// 上传文件类型列表

$uptypes = array (
'image/jpg',
'image/png',
'image/jpeg',
'image/pjpeg',
'image/gif',
'image/bmp',
'image/x-png'
);

$max_file_size = 20000000; //上传文件大小限制,单位BYTE

$destination_folder = 'uploadimg/'; //上传文件路径

$watermark = 1; //是否附加水印(1为加水印,其他为不加水印);

$watertype = 1; //水印类型(1为文字,2为图片)

$waterposition = 1; //水印位置(1为左下角,2为右下角,3为左上角,4为右上角,5为居中);

$waterstring = "http://www.xplore.cn/"; //水印字符串

$waterimg = "xplore.gif"; //水印图片

$imgpreview = 1; //是否生成预览图(1为生成,其他为不生成);

$imgpreviewsize = 1 / 2; //缩略图比例

?>
<html>
<head>
<title>ZwelL图片上传程序</title>
</head>
<body>
<form id="upfile" name="upform" enctype="multipart/form-data" method="post" action="">
<label for="upfile">上传文件:</label>
<input type="file" name="upfile" id="fileField" />
<input type="submit" name="submit" value="上传"/>

</form>

<?php

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
//判断是否有上传文件

if (is_uploaded_file($_FILES['upfile']['tmp_name'])) {
$upfile = $_FILES['upfile'];
print_r($_FILES['upfile']);

$name = $upfilep['name']; //文件名

$type = $upfile['type']; //文件类型

$size = $upfile['size']; //文件大小

$tmp_name = $upfile['tmp_name']; //临时文件

$error = $upfile['error']; //出错原因

if ($max_file_size < $size) { //判断文件的大小

echo '上传文件太大';
exit ();
}

if (!in_arrar($type, $uptypes)) { //判断文件的类型

echo '上传文件类型不符' . $type;
exit ();
}

if (!file_exists($destination_folder)) {
mkdir($destination_folder);
}

if (file_exists("upload/" . $_FILES["file"]["name"])) {
echo $_FILES["file"]["name"] . " already exists. ";
} else {
move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}

$pinfo = pathinfo($name);
$ftype = $pinfo['extension'];
$destination = $destination_folder . time() . "." . $ftype;
if (file_exists($destination) && $overwrite != true) {
echo "同名的文件已经存在了";
exit ();
}

if (!move_uploaded_file($tmp_name, $destination)) {
echo "移动文件出错";
exit ();
}

$pinfo = pathinfo($destination);
$fname = $pinfo[basename];
echo " <font color=red>已经成功上传</font><br>文件名: <font color=blue>" .$destination_folder . $fname . "</font><br>";
echo " 宽度:" . $image_size[0];
echo " 长度:" . $image_size[1];
echo "<br> 大小:" . $file["size"] . " bytes";

if ($watermark == 1) {
$iinfo = getimagesize($destination, $iinfo);
$nimage = imagecreatetruecolor($image_size[0], $image_size[1]);
$white = imagecolorallocate($nimage, 255, 255, 255);
$black = imagecolorallocate($nimage, 0, 0, 0);
$red = imagecolorallocate($nimage, 255, 0, 0);
imagefill($nimage, 0, 0, $white);
switch ($iinfo[2]) {
case 1 :
$simage = imagecreatefromgif($destination);
break;
case 2 :
$simage = imagecreatefromjpeg($destination);
break;
case 3 :
$simage = imagecreatefrompng($destination);
break;
case 6 :
$simage = imagecreatefromwbmp($destination);
break;
default :
die("不支持的文件类型");
exit;
}

image($nimage, $simage, 0, 0, 0, 0, $image_size[0], $image_size[1]);
imagefilledrectangle($nimage, 1, $image_size[1] - 15, 80, $image_size[1], $white);

switch ($watertype) {
case 1 : //加水印字符串

imagestring($nimage, 2, 3, $image_size[1] - 15, $waterstring, $black);
break;
case 2 : //加水印图片

$simage1 = imagecreatefromgif("xplore.gif");
image($nimage, $simage1, 0, 0, 0, 0, 85, 15);
imagedestroy($simage1);
break;
}

switch ($iinfo[2]) {
case 1 :
//imagegif($nimage, $destination);

imagejpeg($nimage, $destination);
break;
case 2 :
imagejpeg($nimage, $destination);
break;
case 3 :
imagepng($nimage, $destination);
break;
case 6 :
imagewbmp($nimage, $destination);
//imagejpeg($nimage, $destination);

break;
}

//覆盖原上传文件

imagedestroy($nimage);
imagedestroy($simage);

}

if ($imgpreview == 1) {
echo "<br>图片预览:<br>";
echo "<img src=\"" . $destination . "\" width=" . ($image_size[0] *$imgpreviewsize) . " height=" . ($image_size[1] * $imgpreviewsize);
echo " alt=\"图片预览:\r文件名:" . $destination . "\r上传时间:\">";
}

}

}
?>
</body>
</html>
你对比一下,就知道原因了,祝你成功

⑸ php验证码字体的问题

//设置字体样式
$font=dirname(__FILE__).'/font/arial.ttf';

$font在提供的代码里其实没有用到,而它正是用来指定字体的。

.ttf文件是一个字体库,这种文件在系统中其实很多,你可以在C盘搜索一下.ttf,也可以到网上去下载喜欢的。

然后将$font赋值为.ttf文件所在的路径,或者将.ttf文件复制到$font设置的路径。


//输出验证码
for($i=0;$i<strlen($_SESSION['code']);$i++){
imagestring($_img,$font_size,$i*$_width/$codelen+mt_rand(1,10),mt_rand(1,$_height/2),$_SESSION['code'][$i],$font_color);
}

这段是画验证码的代码,但是imagestring方法不提供字体设置,要换成imagettftext方法。

修改如下

for($i=0;$i<strlen($_SESSION['code']);$i++){
imagettftext($_img,$font_size,0,$i*$_width/$codelen+mt_rand(1,10),mt_rand(1,$_height/2),$font_color,$font,$_SESSION['code'][$i]);
}

⑹ php图像存在错误显示不出来

看了代码后,有以下提示供参考:


1、从代码中,没有看到输出验证字符图像的代码。


2、建议编写类代码时,添加一个__construct构造函数,用于对上面的 $img 等重要参数进行初始化。


3、代码中生成验证字符的代码有些bug,会造成输出字符不足4个:


$this->code.=$this->charset[mt_rand(0,$_len)];


修正:


$this->code.=$this->charset[mt_rand(0,$_len-1)];


运行结果图:


⑺ php验证码输出全是乱码

看代码是没得问题的,

  1. 访问验证码生成方法/函数的路径不对;

2.文件编码不对,UTF8编码没有去掉BOM头;

3.验证码生成方法有问题。
4.环境不支持。

⑻ 初学php生成图像,输出到浏览器中,看不了图片,是什么问题

<?php
header("content-type:image/png");
$im = @imagecreatetruecolor(120, 20) or die('Cannot Initialize new GD image stream');
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, 'A Simple Text String', $text_color);
imagepng($im);
imagedestroy($im);
?>

你这个是要输出图片,因此只需要这部分就可以了。你的出现乱码是因为你header之前输出了<html><head>等等东西导致header失败。

⑼ php做验证码输出图片显示的是乱码,怎么破

把第一个header()去掉,第二个header()里面写错了
<?php
header("Content-Type:image/jpg");
$image=imagecreate(300,80);
$bgcolor=imagecolorallocate($image,200,60,90);
$write=imagecolorallocate($image,0,0,0);
imagestring($image,5,80,30,"I Like PHP",$write);
imagejpeg($image);
imagedestroy($image);
?>

⑽ PHP写的图形验证码乱码

我吧我的给你用吧

class wxhVerify {

static function imageVerify($length=4, $mode=1, $width=48, $height=22, $verifyName='verify') {
$randval = randomString($length, $mode);
$_SESSION[$verifyName] = md5($randval);
$width = ($length * 10 + 10) > $width ? $length * 10 + 10 : $width;
$im = @imagecreatetruecolor($width, $height);
$r = Array(225, 255, 255, 223);
$g = Array(225, 236, 237, 255);
$b = Array(225, 236, 166, 125);
$key = mt_rand(0, 3);
//随机背景色
$backColor = imagecolorallocate($im, $r[$key], $g[$key], $b[$key]);
//边框色
$borderColor = imagecolorallocate($im, 100, 100, 100);
//点颜色
$pointColor = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
@imagefilledrectangle($im, 0, 0, $width - 1, $height - 1, $backColor);
@imagerectangle($im, 0, 0, $width - 1, $height - 1, $borderColor);
$stringColor = imagecolorallocate($im, mt_rand(0, 200), mt_rand(0, 120), mt_rand(0, 120));
//干扰
for ($i = 0; $i < 10; $i++) {
$fontcolor = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
imagearc($im, mt_rand(-10, $width), mt_rand(-10, $height), mt_rand(30, 300), mt_rand(20, 200), 55, 44, $fontcolor);
}
for ($i = 0; $i < 25; $i++) {
$fontcolor = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
imagesetpixel($im, mt_rand(0, $width), mt_rand(0, $height), $pointColor);
}
for ($i = 0; $i < $length; $i++) {
imagestring($im, 5, $i * 10 + 5, mt_rand(1, 8), $randval{$i}, $stringColor);
}
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
exit;
}

}

//生成随机字符串
function randomString($len=6, $type=1, $addChars='') {
switch ($type) {
case 0:
$chars = '' . $addChars;
break;
case 1:
$chars = str_repeat('0123456789', 3);
break;
case 2:
$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' . $addChars;
break;
case 3:
$chars = 'abcdefghijklmnopqrstuvwxyz' . $addChars;
break;
default :
//默认去掉了容易混淆的字符oOLl和数字01,要增加请使用addChars参数
$chars = '' . $addChars;
break;
}
if ($len > 10) {
//位数过长重复字符串一定次数
$chars = $type == 1 ? str_repeat($chars, $len) : str_repeat($chars, 5);
}
$chars = str_shuffle($chars);
return substr($chars, 0, $len);
}

调用 wxhVerify::imageVerify();

阅读全文

与phpimagestring乱码相关的资料

热点内容
ui设计师与程序员 浏览:415
寿司pdf 浏览:824
pythonbg是什么 浏览:247
c数值算法程序大全 浏览:785
android整点报时 浏览:219
稀土pdf 浏览:534
单片机电子锁 浏览:594
通达信机智资金流指标公式源码 浏览:216
php安装xsl扩展 浏览:840
python如何使用help 浏览:367
上汽荣威app在哪里查询 浏览:901
冰柜压缩机温度108 浏览:718
阿里云邮smtp服务器地址 浏览:250
解压馆认知理解 浏览:239
为什么使用非官方服务器会封号 浏览:9
佛山加密文档软件 浏览:813
港式5张梭哈源码 浏览:241
数据中心pdf 浏览:524
crf源码解析 浏览:855
服务器软件开发是什么意思 浏览:943