为什么我页面是黑色呢?
<?php
$im = imagecreatetruecolor(1000,700); //以指定宽高创建图像资源
$back = imagecolorallocate($im,mt_rand(200,250),mt_rand(200,250),mt_rand(200,250)); //随机色
imagefill($im,0,0,$back); //用随机色填充图像资源
$stringColor = imagecolorallocate($im,0,0,0); //字体颜色
$str = 'abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$str = str_shuffle($str);
$rand_str = substr($str,0,4); //随机数验证码
//在图像中水平写入字符串
//imagestring($im,5,mt_rand(20,imagesx($im)-50),mt_rand(20,imagesy($im)),$rand_str,$stringColor);
//在图像中垂直写入字符串
//imagestringup($im,100,mt_rand(20,imagesx($im)-50),mt_rand(20,imagesx($im)),$rand_str,$stringColor);
imagettftext($im,50,0,mt_rand(20,imagesx($im)-50),mt_rand(10,imagesy($im)),$stringColor,'./technic_.ttf',$rand_str);
header('Content-Type:image/jpeg');
imagejpeg($im);
7
收起
正在回答 回答被采纳积分+1
14回答
雨之赞歌
2019-04-23 11:45:21
IE浏览器
用 imagestring 就可以
<?php
$im = imagecreatetruecolor(1000,600);
$white = imagecolorallocate($im,255,255,255);
$str = 'AHD5';
//imagettftext($im,50,0,mt_rand(20,950),mt_rand(20,550),$white,'comicz.ttf',$str);
imagestring($im,5,500,300,$str,$white);
header('Content-Type:image/jpeg');
imagejpeg($im);
好帮手慕查理
2019-04-23 11:22:02
您好,运行下列代码:
<?php
$im = imagecreatetruecolor(1000,600);
$white = imagecolorallocate($im,255,255,255);
$str = 'AHD5';
imagettftext($im,50,0,mt_rand(20,950),mt_rand(20,550),$white,'comicz.ttf',$str);
header('Content-Type:image/jpeg');
imagejpeg($im);将文件格式调整为在同一目录中:

运行结果为:

请按照上述格式再测试一下。
雨之赞歌
2019-04-22 15:41:12
好像还是不行,我直接用的phpstorm里面的ttf字体文件,

<?php
//print_r(gd_info());
$im = imagecreatetruecolor(1000,600);
$white = imagecolorallocate($im,255,255,255);
$str = 'AHD5';
imagettftext($im,5,0,mt_rand(20,950),mt_rand(20,550),$white,'DroidSerif-Regular.ttf',$str);
header('Content-Type:image/jpeg');
imagejpeg($im);
PHP常用技术与ThinkPHP5框架开发
- 参与学习 人
- 提交作业 225 份
- 解答问题 3372 个
掌握用PHP开发互联网网站的必备功能,掌握当下主流的Linux系统开发,并熟练使用热门框架ThinkPhp开发电商团购项目,是通向PHP工程师必经之路。
了解课程









恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星