簡體   English   中英

標題('Content-Type:image / png'); 不再工作了?

[英]header('Content-Type: image/png'); not working anymore?

我在描述中嘗試了幾次字符串。 但它不斷輸出字符串而不是圖像。 鏈接在這里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轉換的解決方法?

在輸出PNG圖像內容之前,您的PHP腳本會發出UTF-8字節順序標記(EF BB BF)。 此標記可能導致PHP將內容類型默認為text / html。 您的后續調用設置標頭將被忽略,因為PHP已經發送了BOM。

BOM可能已經由文本編輯器放在開始標記之前的PHP腳本中,因為它將文件保存為UTF-8格式。 將編輯器中的格式更改為ANSI / ASCII,以便不寫入BOM。

或者,您可以嘗試在更改標頭之前調用PHP的ob_clean()函數來清除輸出緩沖區。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM