首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用php编辑图片

问如何使用php编辑图片
EN

Stack Overflow用户
提问于 2013-01-21 15:33:46
回答 1查看 2K关注 0票数 0

我写了以下一组代码。

代码语言:javascript
复制
$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);

在运行此代码时,我得到一个错误

代码语言:javascript
复制
The image "http://localhost/app/" cannot be displayed because it contains errors.

请帮帮我。

EN

回答 1

Stack Overflow用户

发布于 2013-01-21 16:04:06

这不是直接的PHP错误,因为您发布的代码是正确的。这很可能是由php tags.之外的某些额外数据引起的

如果这就是文件中的全部内容,它就能正常工作

代码语言:javascript
复制
<?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);
?>

但这不会

代码语言:javascript
复制
<?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 ?>之外没有数据

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14434189

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档