几个月前我启用了GD在本地主机上发挥与它周围一下,发现使用各种脚本联机以获取更好的理解它做什么,都好和好。PHP GD头问题
但现在我觉得我是因为想重复上面有我不断收到标题错误,本地和远程主机上的完全相同的脚本时降入疯狂这里。我想我必须完全忘记如何做到这一点,所以我需要对此进行简要回顾。
例如,这是我曾经尝试过的第一个脚本:
$my_img = imagecreate(200, 80);
$background = imagecolorallocate($my_img, 0, 0, 255);
$text_colour = imagecolorallocate($my_img, 255, 255, 0);
$line_colour = imagecolorallocate($my_img, 128, 255, 0);
imagestring($my_img, 4, 30, 25, "thesitewizard.com",
$text_colour);
imagesetthickness ($my_img, 5);
imageline($my_img, 30, 45, 165, 45, $line_colour);
header("Content-type: image/png");
imagepng($my_img);
imagecolordeallocate($line_color);
imagecolordeallocate($text_color);
imagecolordeallocate($background);
imagedestroy($my_img);
工作得很好回去以后,现在当我运行它,我得到这个:
警告:不能修改标题信息 - 头已经发出(输出开始H:\ XAMPP \ htdocs中\测试\的script.php:1)H:\ XAMPP \ htdocs中\上线11 PNG IHDR测试\ script.php的 P ! # PLTE M )B IDATH 1 0EA N : 8Q JN d Z ��! � ���k�Z⊜���k��g�˕��|K$�M��|)��$ů8DfRQB���-��[I��tźR�+���%�"��Ut)(�K�@dF�e�zKF9&�g|C7i��d��\G�Y � �3y�Ƌ�_�%�����IEND�B
警告:错误的参数计数在H imagecolordeallocate():\ XAMPP \ htdocs中\上线路测试\的script.php 13
警告:imagecolordeallocate()H中错误的参数计数:\ XAMPP \ htdocs中\上线14
测试\ script.php的警告:imagecolordeallocate()H中错误的参数计数:\ XAMPP \ htdocs中\上线测试\ script.php的15
因为我没有试过,第二脚本同样的事情:
// create a 200*200 image
$img = imagecreatetruecolor(200, 200);
// allocate some colors
$white = imagecolorallocate($img, 255, 255, 255);
$red = imagecolorallocate($img, 255, 0, 0);
$green = imagecolorallocate($img, 0, 255, 0);
$blue = imagecolorallocate($img, 0, 0, 255);
// draw the head
imagearc($img, 100, 100, 200, 200, 0, 360, $white);
// mouth
imagearc($img, 100, 100, 150, 150, 25, 155, $red);
// left and then the right eye
imagearc($img, 60, 75, 50, 50, 0, 360, $green);
imagearc($img, 140, 75, 50, 50, 0, 360, $blue);
// output image in the browser
header("Content-type: image/png");
imagepng($img);
// free memory
imagedestroy($img);
那现在输出:
警告:不能更改头信息 - 头已经发出(输出开始H:\ XAMPP \ htdocs中\测试\ script.php的:1)在第22行的H:\ xampp \ htdocs \ tests \ script.php中 “PNG”IHDR“”:9 gIDATx v H a < 4Ƹ ܕ :/ { v } z C ( 〜 ҆ Uj1 jƖ 〜)y [ x JW +/n q 9)eɽɽ %Pfg f s+ I;I l2 s -R u9 b } H d B v R 2 Kr h u v 8 y U | ^O T ' : I* R! r % Z $_ L ʴVd W U ' tk 2 \XA5sΫGL0问:0O | MWĴܼç U】FŹǂUO֝ ά OW z k N“ 1F ”ls {r ? @ /v ZSw1i ? 8-18] CAxN XW죙ۮ9 - ?!& CHN“RB N!&小时,����q�5���v&h,���
& KX \'7lF.-B �Ƃ�ğ'� ^Ajw�1�X0��X"�*��z�.�&"+|{��v/a+0�1o�i0G!l�~�o�+_�� �_��� 8�r|��F���k��!������}>��Ǟ7Xbb=�]�Rd��1��f�d�}�Nـ�k�ۉ���[5�k��6��y��I��jc�~/��˭N�ڍ�� �s�����4L�X0Ac��4L�X0����;�a�Ƃ &h,���
Ƃ%q ,Nh,�Ƃ1���=�V�h,���
,|?C L,�Ƃn�pϮs<&��ơ"��bq2�tX��w�0��h��bb�^����4�¿�+���; �p1�\�_����ܶ�\o�Z�$����Yxz˟Q�O:��
“8 OV | 78 w ^ԸZX(对\ =?y a: N 4 {〜b [S $ U ᡷ ᡷ ֩ ֩ ֩ ֩ ֩ ֩ ֩ ֩ ֩ ֩ ֩ ֩ ֩ ֩ ֩ ֩ ֩ ֩ ֩ ֩ ֩ ֩ ֩ ֩ ֩ ֩ ֩ | } CBf“ K $$ { 3 E^ vMϨc$ڻ f Pu+W + ; { L 6Dލ w G J T c rl n_J E] | m } >an> IEND B`
但是,我曾经尝试过的第三个脚本仍然有效:
// read the post data
$data = array('100','200','300','400','500','350','270');
$x_fld = array('Sun','Mon','Tue','Wen','Thu','Fir','Sat');
$max = 0;
for ($i=0;$i<7;$i++){
if ($data[$i] > $max)$max=$data[$i]; // find the largest data
}
$im = imagecreate(320,255); // width , height px
$white = imagecolorallocate($im,255,255,255); // allocate some color from RGB components remeber Physics
$black = imagecolorallocate($im,0,0,0); //
$red = imagecolorallocate($im,255,0,0); //
$green = imagecolorallocate($im,0,255,0); //
$blue = imagecolorallocate($im,0,0,255); //
//
// create background box
//imagerectangle($im, 1, 1, 319, 239, $black);
//draw X, Y Co-Ordinate
imageline($im, 10, 5, 10, 230, $blue);
imageline($im, 10, 230, 300, 230, $blue);
//Print X, Y
imagestring($im,3,15,5,"Students",$black);
imagestring($im,3,280,240,"Days",$black);
imagestring($im,5,100,50,"Simple Graph",$red);
imagestring($im,5,125,75,"by Vijit",$green);
// what next draw the bars
$x = 15; // bar x1 position
$y = 230; // bar $y1 position
$x_width = 20; // width of bars
$y_ht = 0; // height of bars, will be calculated later
// get into some meat now, cheese for vegetarians;
for ($i=0;$i<7;$i++){
$y_ht = ($data[$i]/$max)* 100; // no validation so check if $max = 0 later;
imagerectangle($im,$x,$y,$x+$x_width,($y-$y_ht),$red);
imagestring($im,2,$x-1,$y+1,$x_fld[$i],$black);
imagestring($im,2,$x-1,$y+10,$data[$i],$black);
$x += ($x_width+20); // 20 is diff between two bars;
}
imagejpeg($im, "graph.jpeg", 90);
imagedestroy($im);
echo "<img src='graph.jpeg'><p></p>";
看来,事实上,它不输出头就是为什么它的工作原理,但为什么别人用来工作,现在不是bey尤其是因为这些错误也在一个不相关的远程主机上复制,我是不是很笨,并且错误地调用脚本?在没有人询问的时候,是的,我确信GD已经完全启用,这里是相关的规范从的phpinfo:
GD支持:启用
GD版本:捆绑(2.0.34兼容)
FreeType的支持:启用
FreeType的联动:对于FreeType
FreeType的版本:2.1.9
T1Lib支持:启用
GIF阅读支持:启用
GIF创造支持:启用
JPG支持:启用
PNG支持:启用
WBMP支持:启用
XBM支持:启用
有人可以请大家指教这个糊涂的女孩?
您是对的,我将脚本的编码更改为UTF-8而不使用BOM,它们都完美无缺地工作。再次感谢! – 2010-09-16 19:20:34
不客气。 – shamittomar 2010-09-16 19:23:19