0

私は次のコードセットを書きました。

$image = ImageCreate(200, 50);
$background_color = ImageColorAllocate($image, 255, 255, 255); // white
$gray = ImageColorAllocate($image, 204, 204, 204); // gray
ImageFilledRectangle($image, 50, 10, 150, 40, $gray);
header('Content-type: image/png');
ImagePNG($image);

このコードの実行中にエラーが発生します

The image "http://localhost/app/" cannot be displayed because it contains errors.

私を助けてください。

4

1 に答える 1

2

PHP投稿したコードは正しいため、これは直接のエラーではありません。これは、ほとんどの場合、外部の余分なデータが原因です。php tags.

これがファイルにあるすべてであれば、動作します

<?php
$image = ImageCreate(200, 50);
$background_color = ImageColorAllocate($image, 255, 255, 255); // white
$gray = ImageColorAllocate($image, 204, 204, 204); // gray
ImageFilledRectangle($image, 50, 10, 150, 40, $gray);
header('Content-type: image/png');
ImagePNG($image);
?>

しかし、これはしません

<?php
//see the new line outside the php tags below? this will break the image.
?>

<?php
$image = ImageCreate(200, 50);
$background_color = ImageColorAllocate($image, 255, 255, 255); // white
$gray = ImageColorAllocate($image, 204, 204, 204); // gray
ImageFilledRectangle($image, 50, 10, 150, 40, $gray);
header('Content-type: image/png');
ImagePNG($image);



//these extra lines wont matter, because they are inside the php tags.


?>

の前に余分なスペースや改行がないことを確認してください<?php。このコードの前にインクルード ファイルがある場合は、そのファイル (ファイル) もチェックして、外部にデータがないことを確認します。<?php ?>

于 2013-01-21T08:04:06.417 に答える