dongying3830 2012-02-29 06:25
浏览 99
已采纳

php标头,内容类型png不起作用

I am having hard time with php headers, i'm trying to create any kind of image in my browser without saving it in a file, but no matter what i do i can't get it working.

So for example if i use this basic example from php manual:

$im = imagecreate(100, 100);

header('Content-Type: image/png');

imagepng($im);
imagedestroy($im);

It would set correct header and even output that icon which u get when image is not found.

Also i use xampp which have GD enabled, here is my phpinfo GD part:

GD Support  enabled
GD Version  bundled (2.0.34 compatible)
FreeType Support    enabled
FreeType Linkage    with freetype
FreeType Version    2.4.3
GIF Read Support    enabled
GIF Create Support  enabled
JPEG Support    enabled
libJPEG Version 6b
PNG Support enabled
libPNG Version  1.2.46
WBMP Support    enabled
XBM Support enabled

Is my code is wrong or do i need to configure something?

  • 写回答

2条回答 默认 最新

  • dpd20130 2012-02-29 06:33
    关注

    You should not only create the image but also fill it some way:

    error_reporting(E_ALL);
    ini_set('display_errors', 1);
    
    $im = imagecreate(100, 100) or die("Cannot Initialize new GD image stream");
    $background_color = imagecolorallocate($im, 0, 0, 0);
    
    header('Content-Type: image/png');
    
    imagepng($im);
    imagedestroy($im);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部