2015-09-19 73 views
0

我想顯示一個圖像從一個變量在PHP中。其次this SO question,但我得到這個,而不是像顯示圖像變量在PHP代碼

�PNG IHDRBMyAPLTE����ٟ�IDAT�c��Z8Y]��Ðf�T%����IEND�B`

這是我的代碼。

$tt_image = imagecreate(100, 50); /* width, height */ 
$background = imagecolorallocatealpha($tt_image, 0, 0, 255, 127); /* In RGB colors- (Red, Green, Blue, Transparency) */ 
header("Content-type: image/png"); 
imagepng($tt_image); 
imagecolordeallocate($background); 
imagedestroy($tt_image); 
+1

你能顯示完整的代碼嗎?包括你獲得png文件到'$ image'的方式。 – DeDee

+0

@DeDee請檢查網頁上的更新回答 – dmSherazi

+0

@SubinThomas,而不是顯示圖片,'PNGIHDRBMyAPLTE 'IDAT c Z8Y]'T%'IEND B ' 打印 – dmSherazi

回答

0

此代碼已檢查並發現工作。您必須在顯示之前編輯圖像。把標題放在顯示圖像的上方。

$tt_image = imagecreate(100, 100); /* width, height */ 
$background = imagecolorallocatealpha($tt_image, 0, 0, 255, 78); //fill some color 
header ('Content-type: image/png'); //image type header 
imagepng($tt_image, NULL, 0);  //disply image 
imagedestroy($tt_image);   //destroy image