0

Joomla 1.5 を使用しています。テキストの上に画像を作成するためのスクリプトがありますが、うまくいきません:

<?php
// Set the content-type
header('Content-Type: image/png');

// Create the image
$im = imagecreatetruecolor(400, 30);

// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);

// The text to draw
$text = 'Testing...';
// Replace path by your own font path
$font = "ARIAL.TFF";

// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);

// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);

// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>

これが機能しない理由がわかりません。Googleで多くの例を見つけて使用しましたが、常に同じです。エラー 英語でのこのエラーは、次を意味しますImage "http://juokoera.lt/a.php" can't be shown, because It have problems (errors)

私はグーグルで見つけました、それは私のホスティングのせいかもしれません、私はそれを変更しましたが、同じ問題です. できれば助けてください。どうもありがとうございました。

更新: コードが次のようになると、同じエラーが発生しました。

dasfasdf
dfas

<?php 
header('Content-Type: image/png');
$im = imagecreatetruecolor(400, 30);
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
$text = 'Testing...';
$font = "ARIAL.TTF";
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
imagepng($im);
imagedestroy($im); ?>

同じphpで追加のテキストを使用するにはどうすればよいですか?

4

1 に答える 1

0

あなたの問題はここにあると思います:

$font = "ARIAL.TFF";

実際、サーバー上に「ARIAL.TFF」という名前のファイルは存在しません。探しているフォント拡張子は TFF ではなく TTF です。実際、サーバー上に「ARIAL.TTF」が存在し、ダウンロードしたところです。その行を次のように修正します。

$font = "ARIAL.TTF";

その後、画像にテキストを書き込むことができるはずです

お役に立てれば

アップデート

質問の更新後、テキストを印刷した後にヘッダーが送信されることに気付きました。

header()ヘッダーを正しく送信するために、関数の前に何も出力する必要はありません。

PHP manual>header()では、最初に説明されているのは次のとおりです。

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include, or require, functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.

于 2013-03-03T11:34:17.397 に答える