简体   繁体   English

WAMP中Gd的PHP问题(imagejpeg不起作用)

[英]PHP issue with Gd in WAMP (imagejpeg doesn't work)

I'm using WAMP 2.2 on windows XP 32bit. 我在Windows XP 32bit上使用WAMP 2.2。 I tried to make simple php script, which draws image, but something went wrong and I came back to simple examples from web. 我试图制作简单的PHP脚本,它绘制图像,但出了点问题,我回到了网上的简单例子。 But even then images don't show (only "blank-image" icon). 但即使这样,图像也不会显示(只有“空白图像”图标)。

Here's example code (from php webpage): 这是示例代码(来自php网页):

<?php 
$im = imagecreatetruecolor(120, 20); 
$text_color = imagecolorallocate($im, 233, 14, 91); 
imagestring($im, 1, 5, 5, 'A Simple Text String', $text_color); 

header('Content-Type: image/jpeg');

imagejpeg($im); 
imagedestroy($im); 
?>

Best thing is when I add second parameter in "imagejpeg" method, which is output file name it actually works: 最好的是当我在“imagejpeg”方法中添加第二个参数时,它实际上是输出文件名:

imagejpeg($im, "output.jpg"); 

Things I tried/checked: 我试过/检查过的事情:

  • php is working (phpinfo()) php正在工作(phpinfo())
  • gd is working (as phpinfo() says and extension is checked in wamp tray->php->extensions->php_gd2) gd正在工作(正如phpinfo()所说,并在wamp tray-> php-> extensions-> php_gd2中检查扩展名
  • without header line I get raw image data, which proofs gd is working 没有标题行我得到原始图像数据,证明gd正在工作
  • tried many other examples, the same result 尝试了很多其他例子,结果相同
  • tried on other browsers 试过其他浏览器
  • tried to restart wamp server 试图重启wamp服务器
  • other php scripts are of course working 其他PHP脚本当然有效
  • tried to enable/check all available error logs, nothing is showing any error 尝试启用/检查所有可用的错误日志,没有任何显示任何错误
  • tried to use this "image" in "img" html object on other page (the same result - "blank/no image" icon) 试图在其他页面上的“img”html对象中使用这个“图像”(相同的结果 - “空白/无图像”图标)

Right now I'm out of ideas. 现在我没有想法。

Please help, Regards ;) 请帮忙,问候;)

Finally found solution by my own. 终于找到了我自己的解决方案。 Php script was saved in "UTF8 encoding", but it has to be "UTF without BOM" (it can be done with notepad++). Php脚本以“UTF8编码”保存,但必须是“没有BOM的UTF”(可以用记事本++完成)。

So it was issue neither with script or wamp configuration, but just wrong encoding. 所以它既不是脚本或wamp配置的问题,而是错误的编码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM