如何在php、Bitnami WAMP和Windows 10中使用gd输出gif图像?

如何在php、Bitnami WAMP和Windows 10中使用gd输出gif图像?,php,gd,gif,Php,Gd,Gif,如何在php、Bitnami WAMP和Windows 10中使用gd输出gif图像? 我可以将其创建为文件,但输出不起作用 似乎我收到了错误,因为没有文件。 主机后的参数(public/index.php/test/img11)用于访问控制器操作。 真正的文件是/type705b/src/Bundle/Resources/views/test/img/ImageOutputingError.php $width = 150; $height = 150; $img = imagecreate(

如何在php、Bitnami WAMP和Windows 10中使用gd输出gif图像? 我可以将其创建为文件,但输出不起作用

似乎我收到了错误,因为没有文件。
主机后的参数(public/index.php/test/img11)用于访问控制器操作。 真正的文件是/type705b/src/Bundle/Resources/views/test/img/ImageOutputingError.php

$width = 150;
$height = 150;
$img = imagecreate($width, $height);

//Create image background
//$white = ImageColorAllocate($img, 255, 255, 255);
//$black = ImageColorAllocate($img, 0, 0, 0);
//$red   = ImageColorAllocate($img, 255, 0, 0);
$blue  = imagecolorallocate($img, 0, 0, 255); 
ImageFill($img,$width,$height,$blue); 

header('Content-type: image/gif');
imagegif($img);
imagedestroy($img);
imagecolordeallocate($img, $blue); 
也许我必须更正
.htaccess
并启用图像支持

Options -MultiViews
Options -Indexes

Options +FollowSymlinks
RewriteEngine on
RewriteBase /public/
IndexIgnore * 

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{ENV:REQUEST_FILENAME} !-d
RewriteCond %{ENV:REQUEST_FILENAME} !-f
RewriteCond %{ENV:REQUEST_FILENAME} !-l

RewriteRule ^index.php?(.+)$ index.php?url=$1 [QSA,L] 
在我的例子中,图像没有在Chrome和Opera中显示,在Firefox中产生错误“图像,无法显示,因为它包含错误”,并在Explorer中显示带有十字的小正方形

Inspector显示此标记(我犯了一个错误“| | body,| | img”)以将其显示为代码:

    || body style="margin: 0px; background: #0e0e0e;">
|| img style="-webkit-user-select: none;background-position: 0px 0px, 10px 10px;background-size: 20px 20px;background-image:linear-gradient(45deg, #eee 25%, transparent 25%, transparent 75%, #eee 75%, #eee 100%),linear-gradient(45deg, #eee 25%, white 25%, white 75%, #eee 75%, #eee 100%);" src="http://localhost/type705b/public/index.php/test/img11">
</body>
ImageCreatingWorking.php

//This one works, but i want to output, versus file creation

$width = 150;
$height = 150;
$img = imagecreate($width, $height);
$blue  = imagecolorallocate($img, 0, 0, 255); 
ImageFill($img,$width,$height,$blue); 
imagegif($img, __DIR__ .'/trial.gif' );
imagedestroy($img);
imagecolordeallocate($img, $blue); 
/* *phpinfo()

PHP版本5.6.30

启用GD支持

捆绑的GD版本(2.1.0兼容)


*/

尝试删除
imagecolordeallocate($img,$blue);
(最后一行)。这是无用的,会产生警告,因为您已经销毁了
$img
。尽管代码对我有效

如果这没有帮助,请尝试注释php文件中的
标题('Content-type:image/gif');
行。它将在浏览器中以文本形式显示图像内容,然后查看是否没有显示任何错误。通常它应该以GIF87a开始,然后是一些不可读的胡言乱语。如果在“GIF87a”之前有任何内容,它将阻止浏览器显示图像。例如,一些php警告或通知

代码本身看起来很好,对我很有用


它不应该与.htaccess文件有任何关系。浏览器理解它正在查看图像,这意味着它已到达正确的url并收到内容类型标题。但由于某些原因,内容不是有效的GIF。

尝试删除
imagecolordeallocate($img,$blue)(最后一行)。它是无用的,会产生警告,因为您已经销毁了
$img
。尽管代码对我有用

如果没有帮助,试着注释掉
标题('Content-type:image/gif')行。它将在浏览器中以文本形式显示图像内容,然后查看是否在那里显示任何错误。通常它应该以GIF87a开头,然后是一些不可读的胡言乱语。如果在“GIF87a”之前有内容,则会阻止浏览器显示图像。例如,一些php警告或通知

代码本身看起来很好,对我很有用


它不应该与.htaccess文件有任何关系。浏览器理解它正在查看图像,这意味着它已到达正确的url并收到内容类型标题。但由于某些原因,内容不是有效的GIF。

谢谢。我将
ImageOutputingError.php
放在localhost目录中,并使用直接url localhst/ImageOutputingError.php——这很有效。只有将其包含在自己的框架操作中,它才起作用。很可能是邮件头发送错误,或者我在某个地方回发了smth,这会阻止图像显示。谢谢。我将
ImageOutputingError.php
放在localhost目录中,并使用直接url localhst/ImageOutputingError.php——这很有效。只有将其包含在自己的框架操作中,它才起作用。最可能的情况是,标题发送错误,或者我在某个地方回显了smth,这会阻止图像显示。
FreeType Support    enabled
FreeType Linkage    with freetype
FreeType Version    2.7.0
GIF Read Support    enabled
GIF Create Support  enabled
JPEG Support    enabled
libJPEG Version 9 compatible
PNG Support enabled
libPNG Version  1.5.26
WBMP Support    enabled
XPM Support enabled
libXpm Version  30411
XBM Support enabled
WebP Support    enabled