问题描述
我已经尝试过几次描述中的字符串.但是它会继续输出字符串而不是图像.链接在此处 http://wenti.de/resize.php .
I have tried several times the string in the description. But it keeps outputting a string instead of an image. Link is here http://wenti.de/resize.php.
下面是源代码,
$my_img = imagecreate( 200, 80 );
$background = imagecolorallocate( $my_img, 0, 0, 255 );
$text_colour = imagecolorallocate( $my_img, 255, 255, 0 );
$line_colour = imagecolorallocate( $my_img, 128, 255, 0 );
imagestring( $my_img, 4, 30, 25, "thesitewizard.com",
$text_colour );
imagesetthickness ( $my_img, 5 );
imageline( $my_img, 30, 45, 165, 45, $line_colour );
header( "Content-type: image/png" );
imagepng( $my_img );
imagecolordeallocate( $line_color );
imagecolordeallocate( $text_color );
imagecolordeallocate( $background );
imagedestroy( $my_img );
是否存在不进行base64转换的解决方法?
Is there a workaround without base64 conversion?
推荐答案
您的PHP脚本在输出PNG图像内容之前会发出UTF-8字节顺序标记(EF BB BF).此标记可能导致PHP将内容类型默认为text/html.您后续的设置标头的调用将被忽略,因为PHP已经发送了BOM.
Your PHP script is emitting a UTF-8 byte order mark (EF BB BF) before outputting the PNG image content. This marker is probably causing PHP to default the content type to text/html. Your subsequent call to set the header is ignored because PHP has already sent the BOM.
BOM可能已经由文本编辑器放置在PHP脚本中的开始标记之前,因为它会将文件保存为UTF-8格式.将编辑器中的格式更改为ANSI/ASCII,以便不编写BOM.
The BOM has probably been placed in your PHP script just before the opening tag by your text editor, because it's saving the file in UTF-8 format. Change the format in your editor to ANSI/ASCII so that the BOM is not written.
或者,您可以尝试在更改标头之前调用PHP的ob_clean()
函数清除输出缓冲区.
Alternatively, you could try calling PHP's ob_clean()
function to clear the output buffer before changing the header.
这篇关于header('Content-Type:image/png');不再工作了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!