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 ?>