2017-05-13 9 views
1

Bitnami WAMP、Windows 10でgdイメージを出力するには? ファイルとして作成できますが、出力は機能しません。Bitnami WAMP、Windows 10でgdイメージを出力するには?

ファイルがないため、エラーが発生しています。http://localhost/type705b/public/index.php/test/img11
ホストの後のパラメータ(public/index.php/test/img11)は、コントローラアクションにアクセスするために使用されます。 実際のファイルは

たぶん私は.htaccessを修正し、画像のサポートを有効にする必要が/type705b/src/Bundle/Resources/views/test/img/ImageOutputingError.php

はありますか?私の場合は

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を、それが誤りを含んでいるため表示できません」と、エクスプローラのクロスを持つ小さな正方形が表示されます。

インスペクタは、コードとして表示する(iは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サポートが

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 
(2.1.0互換)同梱

GDのバージョンを有効に

*/

答えて

0

imagecolordeallocate($img, $blue);(最終行)。 $imgを既に破壊しているので、それは役に立たず、警告を発する。とにかくコードは私のために働いていますが。

それでも問題が解決しない場合は、PHPファイルのheader('Content-type: image/gif');行をコメントアウトしてみてください。ブラウザの画像内容をテキストとして表示し、エラーが表示されていないかどうかを確認します。通常はGIF87aで始まり、読めないぎこちないものから始めるべきです。 「GIF87a」の前に何かがあると、ブラウザが画像を表示しないようになります。たとえば、いくつかのPHPの警告または通知。

コード自体は問題なく機能していると思われます。

.htaccessファイルとは関係がありません。ブラウザは画像を見ていることを理解しています。つまり、ブラウザは正しいURLに達し、コンテンツタイプヘッダを受け取りました。しかし何らかの理由でコンテンツが有効なGIFではありません。

+0

ありがとうございます。 'ImageOutputingError.php'をlocalhostディレクトリに置き、直接URL localhst/ImageOutputingError.phpを使います。これはうまくいきます。独自のフレームワークアクションに含める場合にのみ機能します。たぶんヘッダーが間違って送信されるか、どこかで画像が表示されないようにします。 –

関連する問題