我查看phpinfo可以看到:gd
GD Support enabled
GD Version 2.0 or higher
FreeType Support enabled
FreeType Linkage with freetype
FreeType Version 2.3.9
T1Lib Support enabled
GIF Read Support enabled
GIF Create Support enabled
JPG Support enabled
PNG Support enabled
WBMP Support enabled
然后写了个test.php.文件内容:<?php
header("Content-type: image/png");
$im=ImageCreate(30, 20);
//or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 0, 0, 0);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5,"A Simple Text String",$text_color);
imagepng($im);
imagedestroy($im);
?> 运行后提示下载test.php...下载完成后查看了内容原来是错误提示:<br />
<b>Warning</b>: imagecreate() [<a href='function.imagecreate'>function.imagecreate</a>]: Invalid image dimensions in <b>/var/www/phptest/1.php</b> on line <b>3</b><br />
<br />
<b>Fatal error</b>: Call to undefined function imagecolorallocate() in <b>/var/www/phptest/1.php</b> on line <b>5</b><br />
GD Support enabled
GD Version 2.0 or higher
FreeType Support enabled
FreeType Linkage with freetype
FreeType Version 2.3.9
T1Lib Support enabled
GIF Read Support enabled
GIF Create Support enabled
JPG Support enabled
PNG Support enabled
WBMP Support enabled
然后写了个test.php.文件内容:<?php
header("Content-type: image/png");
$im=ImageCreate(30, 20);
//or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 0, 0, 0);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5,"A Simple Text String",$text_color);
imagepng($im);
imagedestroy($im);
?> 运行后提示下载test.php...下载完成后查看了内容原来是错误提示:<br />
<b>Warning</b>: imagecreate() [<a href='function.imagecreate'>function.imagecreate</a>]: Invalid image dimensions in <b>/var/www/phptest/1.php</b> on line <b>3</b><br />
<br />
<b>Fatal error</b>: Call to undefined function imagecolorallocate() in <b>/var/www/phptest/1.php</b> on line <b>5</b><br />
请问php.ini中怎么配置.
我现在在php.ini中手动添加了两行.
extension_dir="/usr/lib/php5/20060613+lfs/"
extension=gd.so现在没有报错了,不过我不知道输出的结果是否正确.
我的代码是:<?php
//header("Content-Type: image/png"); 如果添加这行,提示下载文件,打开后和在浏览器中看到的一样.
$im= imagecreate( 300, 200);
$bg_color= imagecolorallocate($im, 210, 210, 210);
$text_color= imagecolorallocate($im, 23, 14, 91);
imagestring($im, 1, 5, 5,"A Simple Text String", $text_color);
imagepng($im);
imagedestroy($im);
?>
在浏览器中看到的是:
�PNG ��� IHDR��,�������hN���PLTE���[��I�����IDATX���!�@@�ai� M1�4)�T QGRQ��V�JP�F���#�jkp�?1�g2#��Ϩڪ� #���j7��7nZ$M��*��mA���Ԩ�t�gv�eaӋ�F�O��2*��:q37�pv�=��A�8�*߸�6_��>�o������������Wo��Q���9����IEND�B`� 我看例子中给的,结果应该是一张图片阿,不知道为什么不是.
-20060613+lfs
ubuntu的/usr/lib/php5/下只有三个文件:
-20060613+lfs
-libexec
-maxlifetime
在20060613+lfs下可以看到gd.so.然后我又测试了下其他的函数.<?php
$image=imagecreatefrompng("1.png");
header("Content-type: image/png");
imagepng($image);
imagedestroy($image);
?>
这个时候可以在浏览器中看到1.png一样的图片.根据4楼最后输出的乱码,我猜测是因为png文件信息不完整,才导致输出的时候是一些乱码而不是图片...不知道对不对.而在php 手册上看到的例子似乎都没有说这个问题,直接输出就应该可以得到图片...
用ultraedit查看,和其他的png图片对比,发现二进制数据最后多了两个字节:0x0A20.普通的Png图片最后都是以0x8260结尾的.
这是为什么呢?
用imagecreatefrompng("1.png");创建图片是没有问题的,我觉得设置应该没问题了.