【发布时间】:2017-10-12 12:01:59
【问题描述】:
如何在 php、Bitnami WAMP、Windows 10 中输出带有 gd 的 gif 图像? 我可以将其创建为文件,但无法输出。
似乎出现错误,因为没有文件http://localhost/type705b/public/index.php/test/img11。
主机后面的参数(public/index.php/test/img11),用于访问控制器动作。
真正的文件是/type705b/src/Bundle/Resources/views/test/img/ImageOutputingError.php
也许我必须更正.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 中产生错误“图像http://localhost/type705b/public/index.php/test/img11,无法显示,因为它包含错误”,并在资源管理器中显示带有十字的小方块。
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>
背景图像没有我在脚本中使用的颜色:#0000FF; .
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);
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兼容)
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
*/
【问题讨论】: