<?php
//check we have the appropriate variable data
//variables are button-text and color$button_text=$_REQUEST['button_text'];
$color=$_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;
}
//create an image of the right background and check size
$im=imagecreatefrompng($color.'-button.png');
if(!$im)
{
echo 'Could not create image';
exit;
}
$width_image=imagesx($im);
$height_image=imagesy($im);
//our images need an 18 pixel margin in from the edage of the image
$width_image_wo_margins=$width_image-(2*18);
$height_image_wo_margins=$height-(2*18);
//work our if the font size will fit and make itsmaller until it does
//start our with the biggest size that will reasonably fit on our buttons
$font_size=3;
//you need to tell GD2 where fonts reside
putenv('GDFONTFATH=C:\windows\fonts');
$fontname='Arial';
do
{
$font_size--;
//find out the size of the text at that font size
$bbox =imagettfbbox($font_size,0,$fontname,$button_text);
$right_text=$bbox[2];//right co-ordinate
$left_text=$bbox[0];
$width_text=$right_text-$left_text; //how wide is it?
$height_text=abs($bbox[7]-$bbox[1]);//how tall is it?
}
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)
{
//no readable font size will fit on button
echo 'Text given will not fit on button.<br/>';
}
else
{
//we have found a font size that will fit
//now work out where to put it
$text_x=$width_image/2.0-$width_text/2/0;
$text_y=$height_image/2.0-$height_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);
?>
Warning: imagettfbbox() [function.imagettfbbox]: Invalid font filename in E:\AppServ\www\make_button.php on line 38
//check we have the appropriate variable data
//variables are button-text and color$button_text=$_REQUEST['button_text'];
$color=$_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;
}
//create an image of the right background and check size
$im=imagecreatefrompng($color.'-button.png');
if(!$im)
{
echo 'Could not create image';
exit;
}
$width_image=imagesx($im);
$height_image=imagesy($im);
//our images need an 18 pixel margin in from the edage of the image
$width_image_wo_margins=$width_image-(2*18);
$height_image_wo_margins=$height-(2*18);
//work our if the font size will fit and make itsmaller until it does
//start our with the biggest size that will reasonably fit on our buttons
$font_size=3;
//you need to tell GD2 where fonts reside
putenv('GDFONTFATH=C:\windows\fonts');
$fontname='Arial';
do
{
$font_size--;
//find out the size of the text at that font size
$bbox =imagettfbbox($font_size,0,$fontname,$button_text);
$right_text=$bbox[2];//right co-ordinate
$left_text=$bbox[0];
$width_text=$right_text-$left_text; //how wide is it?
$height_text=abs($bbox[7]-$bbox[1]);//how tall is it?
}
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)
{
//no readable font size will fit on button
echo 'Text given will not fit on button.<br/>';
}
else
{
//we have found a font size that will fit
//now work out where to put it
$text_x=$width_image/2.0-$width_text/2/0;
$text_y=$height_image/2.0-$height_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);
?>
Warning: imagettfbbox() [function.imagettfbbox]: Invalid font filename in E:\AppServ\www\make_button.php on line 38
解决方案 »
- 关于appache的问题
- 如何修改CentOS中PDO的设置
- 那里有免费的php源码下载,100分结帐。
- wamp2.4-x86.exe安装出错
- php刷新页面提示是否提交表单
- setcookie错误?Cannot modify header information
- 请给一个 xor 互斥逻辑运算的例子, 和~ 位互斥操作运算
- 给PHP脚本加密,请进,谢谢。
- PHP 利用MongoDB GridFS存储大文件遇到的问题???有没有人遇到过。
- MySQL server error report:Array ( [0] => Array错误
- Fatal error:Call to a member function setFetchMode() on a non-object
- PHP电台,实时传播,自己有电台,如何播放
我把putenv('GDFONTFATH=C:\windows\fonts');
改成putenv('GDFONTFATH=C:\Windows\Fonts');
报错为:Warning: imagettfbbox() [function.imagettfbbox]: Could not find/open font in E:\AppServ\www\make_button.php on line 38
但是在文件夹中的确有Arial字体文件请大侠帮助!~~~
报错一直为 Warning: imagettfbbox() [function.imagettfbbox]: Invalid font filename in E:\AppServ\www\make_button.php on line 38
putenv('GDFONTFATH=C:\windows\fonts');
$fontname='Arial';直接改成
$fontname = 'c:/windows/fonts/arial.ttf'就可以了,大小写不敏感。
Warning: imagettfbbox() [function.imagettfbbox]: Invalid font filename in D:\xampp\htdocs\test\class\pImage.class.php on line 211Warning: imagettftext() [function.imagettftext]: Invalid font filename in D:\xampp\htdocs\test\class\pDraw.class.php on line 1023 我的问题出现在调用的类里面,,你们怎么看?