php标题('内容类型:image / jpeg')显示了borken图像

时间:2015-08-20 05:02:18

标签: php image header jpeg content-type

我正在尝试使用电子邮件地址作为图片。

我写了以下代码:

    private void MakeAvi(List<Bitmap> maps)
    {
        AviManager mana = new AviManager("local.avi", false);

        //false means do not show the diag of the Compression 
        //21 means the fps of the video
        //maplist[0] cover of the video  the maplist is the val you should insert 
        VideoStream avistream = mana.AddVideoStream(false, 21, maplist[0]);

        for (int i = 1; i < maps.Count; i++)
        {
            avistream.AddFrame(maplist[i]);
        }

        mana.Close();
        MessageBox.Show("AddOk");
    }

我用Google搜索并尝试了以下解决方案。

  1. Gd p库已配置并正常工作。

  2. 我清除了浏览器缓存。

  3. 我已经在php手册上检查了所有功能。

  4. <?php header('Content-type: image/jpeg'); echo $email= 'ali@alipakistani90.com'; echo $email_length= strlen($email); echo $font_size= 4; echo $image_height= imagefontheight($font_size); echo $image_width= imagefontwidth($font_size) * $email_length; $image= imagecreate($image_width, $image_height); imagecolorallocate($image, 255, 255, 255); $font_color= imagecolorallocate($image, 0, 0, 0); imagestring($image, $font_size, 0, 0, $email, $font_color); imagejpeg($image); ?>

    Please Note: I also get broken image when I only the following code:

    我的gd配置:

    header('Content-type: image/jpeg');

    感谢您的努力。 感谢

2 个答案:

答案 0 :(得分:1)

正如@Ultimaer所提到的,您应该删除所有echo es。您的代码会在图像数据之上放置一些信息,这可能就是它看起来破碎的原因。

以下是工作来源:

<?php
header('Content-type: image/jpeg');

$email= 'test@test.com';
$email_length= strlen($email);
$font_size= 4;

$image_height= imagefontheight($font_size);
$image_width= imagefontwidth($font_size) * $email_length;

$image= imagecreate($image_width, $image_height);

imagecolorallocate($image, 255, 255, 255);

$font_color= imagecolorallocate($image, 0, 0, 0);

imagestring($image, $font_size, 0, 0, $email, $font_color);

imagejpeg($image);

答案 1 :(得分:0)

删除echo关键字并尝试。

$email= 'ali@alipakistani90.com';
$email_length= strlen($email);
$font_size= 4;

$image_height= imagefontheight($font_size);
$image_width= imagefontwidth($font_size) * $email_length;

$image= imagecreate($image_width, $image_height);

imagecolorallocate($image, 255, 255, 255);

$font_color= imagecolorallocate($image, 0, 0, 0);

imagestring($image, $font_size, 0, 0, $email, $font_color);

header('Content-type: image/jpeg');

imagejpeg($image);
imagedestroy($image);
相关问题