我编写了这个函数来从文本创建 png 文件:
function pngfromtext($text){
$fontsize = 5;
$width = imagefontwidth($fontsize)* strlen($text);
$height = imagefontheight($fontsize);
$img = imagecreate($width, $height);
// Transparent background
$black = imagecolorallocate($img, 0, 0, 0);
imagecolortransparent($img, $black);
// Red text
$red = imagecolorallocate($img, 255, 255, 255);
imagestring($img, $fontsize, 0, 0, $text, $red);
header('Content-type: image/png');
imagepng($img);
imagedestroy($img);
}
我将代码写入functions.php
文件,在另一个页面中使用此功能时出现此错误:
Warning: Cannot modify header information - headers already sent by (output started at ..\functions.php on line 58
�PNG IHDRZ^%JPLTE����ٟ�tRNS@��f�IDAT�c` Hȱ�7�H��'��`c��s�����i��$���Hl`8��Ɛ�� ��#�c��p�� q�3f�òm�� �g�ـ�6fF ���h�bc�sXd4c�A4����?|�¦����r+���!IEND�B`�
怎么了?