簡體   English   中英

如何在php,Bitnami WAMP,Windows 10中使用gd輸出gif圖像?

[英]How to output a gif image with gd in php, Bitnami WAMP, Windows 10?

如何在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>

其中background-image沒有我在我的腳本中使用的顏色:#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

* /

嘗試刪除imagecolordeallocate($img, $blue); (最后一行)。 它沒用,並產生警告,因為你已經銷毀了$img 雖然代碼對我來說無論如何都有用。

如果這沒有幫助,請嘗試注釋掉header('Content-type: image/gif'); 你的PHP文件中的行。 它將在瀏覽器中以文本形式顯示圖像內容,然后查看它是否顯示任何錯誤。 通常它應該從GIF87a開始,然后是一些難以理解的亂碼。 如果在“GIF87a”之前有某些內容,則會阻止瀏覽器顯示圖像。 例如一些php警告或通知。

代碼本身似乎很好,並為我工作。

它不應該與.htaccess文件有任何關系。 瀏覽器理解它正在查看圖像,這意味着它已經到達了正確的URL並收到了內容類型標題。 但由於某種原因,內容不是有效的GIF。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM