【发布时间】:2014-03-25 01:41:17
【问题描述】:
我正在尝试制作图像生成器 php 文件并使用此代码>
<?php
header('content-type: image/jpeg');
$email = 'example@example.com';
$email_length = strlen($email);
$font_size = 4;
$image_height = imagefontheight($font_size);
$image_width = imagefontheight($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);
?>
当我在 Chrome 中加载文件时,它没有显示图像。在 Mozilla 中,它显示错误“图像“...”无法显示,因为它包含错误”。但是当我把 imagejpeg($image,"new.jpg");而不是 imagejpeg($image);它使img文件正确。有谁知道我应该怎么做才能解决这个问题?
【问题讨论】:
-
显示的可能是 PHP 解析错误,因为您已将内容类型设置为图像。我已经在本地运行了,它似乎工作正常,我建议你注释掉
header调用并直接运行脚本以查看是否有任何 PHP 错误出现。 -
我试过了,它没有显示错误,但浏览器中有原始数据。
标签: php