运行后提示如下警告并没有输出预计结果,请教如何解决Warning: imagettfbbox() [function.imagettfbbox]: Invalid font filename in F:\AppServ\www\make_button.php on line 34Warning: imagettftext() [function.imagettftext]: Invalid font filename in F:\AppServ\www\make_button.php on line 63Warning: Cannot modify header information - headers already sent by (output started at F:\AppServ\www\make_button.php:34) in F:\AppServ\www\make_button.php on line 65
‰PNG ��� IHDR��� ���P���©ƒŽ��ƒPLTE£=jÛ¿r·–U^ZuN±ëy†™L‘b‹H`„RFCå ÖÁ¥eA;Pê â è ã Ôdä Ÿß ÎÒ¤¼ýüüÙÈÉç À@|Õæ Ȧ¦b55á Ó¾¬¬¸¯Ìûùù³üÙÙ¦ózzÈxxšttæ##ÜAy$$Ëa**õ««¦]]Ø»¦¦ò``¤……ƒ[[›]]©©Ü..mJ õÙÙRð¨¨i áØؼ©©úùùÒªªþùùó±±ø±±ž++e88h88“ssö‘‘í``ï==ßÕÕä__ ……ì|UU~XX‘((t'' ï::W##å;;Aÿüüÿÿÿë ÿÿÿÍ>¦÷��)IDATxœíÙWsÚ@†a °0`ŠG;YªèÕ½¤÷Þ{ï=N‘ÿz Æñ‚Ç3>»™9ïØgöò;‚ËykÀ^!¡!¡!¡í�þzvesr‹edróÍÓÊnÀ£o™âþFÆ;ã¯?²Æý‰ô¤s§Ç³– 3E߉QàÂ6Œ¥rþ1 |rŠ eË—u x/ÇÚµ].™vRóð½ÎšµžLgR×)àMÞ€g)à%Þ€÷)`’7à,÷¡!¡!¡!¡!¡!Úÿ�tF€ž¶™NSHe) mñµnui`Éà8ØÛ1 X,˜¬aÃk$¤RÀºÔãäIOª£Þ�lچɅ˜†ÝÌ„= ܨWaN$¤aUëþvL£€ÇVÖª‹ºÉ–Hˆ©/V×V¾…oîRÀ炯¶$+§3+gi©æâªvž^ŒçƒrX²;IvÙ¥bMæ㱃‰kpÞ{Àï¬úÊršarÙ·êøÃÞ¾oî2\ÿê …£‘¼ d˜åùH4ò¨}ß÷Gн¡L{¼¡v7Å°n;äõL+ÚÌñ¡KÝ“šPcÙì,³²Ù˜P´Ä¡–øÊV®ÞNLiýŽ0jðöTb¦Ïûù¡2èº^¶æ×j‰¢øâÝ?¨÷Êòç…ÃŒ[ø´¼ëÅË Ð Ð Ðí7]Õ®•P����IEND®B`‚
代码如下,需要个png文件。
<?php$button_text=Microsoft;//$_REQUEST['button_text'];
$color='red';//$_REQUEST['color'];if((empty($button_text)||empty($color))||(!($color=='red'||$color=='blue'||$color=='green')))
{
echo 'Could not create image - form not filled out correctly';
exit;
}$im = ImageCreateFromPNG($color.'-button.png');
if(!$im)
{
echo 'Could not create image';
exit;
}$width_image=ImageSX($im);
$height_image=ImageSY($im);$width_image_wo_margins = $width_image - (2*18);
$height_image_wo_margins = $height_image - (2*18);$font_size = 33;putenv('GDFONTPATH=C:\WINDOWS\Fonts');
$fontname= 'arial';do
{
$font_size--;$bbox=ImageTTFBBox($font_size,0,$fontname,$button_text);$right_text=$bbox[2];
$left_text=$bbox[0];
$width_text=$right_text-$left_text;
$heght_text=abs($bbox[7]-$bbox[1]);
}
while($font_size>8&&
($height_text>$height_image_wo_margins||
$width_text>$width_image_wo_margins)
);
if($height_text>$height_image_wo_margins||
$width_text>$width_image_wo_margins)
{
echo 'Text given will not fit on button.<br/>';
}
else
{
$text_x=$widht_image/2.0-$widht_text/2.0;
$text_y=$height_image/2.0-$heihgt_text/2.0;
if($left_text<0)
$text_x += abs($left_text);
$above_line_text=abs($bbox[7]);
$text_y += $above_line_text;
$text_y -=2;
$white=ImageColorAllocate($im,255,255,255);
ImageTTFText($im,$font_size,0,$text_x,$text_y,$white,$fontname,$button_text);
Header('Content-type;image/png');
ImagePng($im);
}
ImageDestroy($im);
?>
‰PNG ��� IHDR��� ���P���©ƒŽ��ƒPLTE£=jÛ¿r·–U^ZuN±ëy†™L‘b‹H`„RFCå ÖÁ¥eA;Pê â è ã Ôdä Ÿß ÎÒ¤¼ýüüÙÈÉç À@|Õæ Ȧ¦b55á Ó¾¬¬¸¯Ìûùù³üÙÙ¦ózzÈxxšttæ##ÜAy$$Ëa**õ««¦]]Ø»¦¦ò``¤……ƒ[[›]]©©Ü..mJ õÙÙRð¨¨i áØؼ©©úùùÒªªþùùó±±ø±±ž++e88h88“ssö‘‘í``ï==ßÕÕä__ ……ì|UU~XX‘((t'' ï::W##å;;Aÿüüÿÿÿë ÿÿÿÍ>¦÷��)IDATxœíÙWsÚ@†a °0`ŠG;YªèÕ½¤÷Þ{ï=N‘ÿz Æñ‚Ç3>»™9ïØgöò;‚ËykÀ^!¡!¡!¡í�þzvesr‹edróÍÓÊnÀ£o™âþFÆ;ã¯?²Æý‰ô¤s§Ç³– 3E߉QàÂ6Œ¥rþ1 |rŠ eË—u x/ÇÚµ].™vRóð½ÎšµžLgR×)àMÞ€g)à%Þ€÷)`’7à,÷¡!¡!¡!¡!¡!Úÿ�tF€ž¶™NSHe) mñµnui`Éà8ØÛ1 X,˜¬aÃk$¤RÀºÔãäIOª£Þ�lچɅ˜†ÝÌ„= ܨWaN$¤aUëþvL£€ÇVÖª‹ºÉ–Hˆ©/V×V¾…oîRÀ炯¶$+§3+gi©æâªvž^ŒçƒrX²;IvÙ¥bMæ㱃‰kpÞ{Àï¬úÊršarÙ·êøÃÞ¾oî2\ÿê …£‘¼ d˜åùH4ò¨}ß÷Gн¡L{¼¡v7Å°n;äõL+ÚÌñ¡KÝ“šPcÙì,³²Ù˜P´Ä¡–øÊV®ÞNLiýŽ0jðöTb¦Ïûù¡2èº^¶æ×j‰¢øâÝ?¨÷Êòç…ÃŒ[ø´¼ëÅË Ð Ð Ðí7]Õ®•P����IEND®B`‚
代码如下,需要个png文件。
<?php$button_text=Microsoft;//$_REQUEST['button_text'];
$color='red';//$_REQUEST['color'];if((empty($button_text)||empty($color))||(!($color=='red'||$color=='blue'||$color=='green')))
{
echo 'Could not create image - form not filled out correctly';
exit;
}$im = ImageCreateFromPNG($color.'-button.png');
if(!$im)
{
echo 'Could not create image';
exit;
}$width_image=ImageSX($im);
$height_image=ImageSY($im);$width_image_wo_margins = $width_image - (2*18);
$height_image_wo_margins = $height_image - (2*18);$font_size = 33;putenv('GDFONTPATH=C:\WINDOWS\Fonts');
$fontname= 'arial';do
{
$font_size--;$bbox=ImageTTFBBox($font_size,0,$fontname,$button_text);$right_text=$bbox[2];
$left_text=$bbox[0];
$width_text=$right_text-$left_text;
$heght_text=abs($bbox[7]-$bbox[1]);
}
while($font_size>8&&
($height_text>$height_image_wo_margins||
$width_text>$width_image_wo_margins)
);
if($height_text>$height_image_wo_margins||
$width_text>$width_image_wo_margins)
{
echo 'Text given will not fit on button.<br/>';
}
else
{
$text_x=$widht_image/2.0-$widht_text/2.0;
$text_y=$height_image/2.0-$heihgt_text/2.0;
if($left_text<0)
$text_x += abs($left_text);
$above_line_text=abs($bbox[7]);
$text_y += $above_line_text;
$text_y -=2;
$white=ImageColorAllocate($im,255,255,255);
ImageTTFText($im,$font_size,0,$text_x,$text_y,$white,$fontname,$button_text);
Header('Content-type;image/png');
ImagePng($im);
}
ImageDestroy($im);
?>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货