我写了以下一组代码。
$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.请帮帮我。
发布于 2013-01-21 16:04:06
这不是直接的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 ?>之外没有数据
https://stackoverflow.com/questions/14434189
复制相似问题