//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.
';
}
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 $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
回复讨论(解决方案)
没有那个字体 换一个字体或把字体文件拷到相对应的目录
在C盘路径下 有arial字体文件啊。
我把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'就可以了,大小写不敏感。
我也遇到了这种情况,也按照#4楼的做了,还是出现那种情况,找不到文件名
字体路径的反斜杠是怎么写的,是\还是/,我试了好几种,都不行,并且字体在系统中存在
Warning: imagettfbbox() [function.imagettfbbox]: Invalid font filename in D:\xampp\htdocs\test\class\pImage.class.php on line 211
Warning: imagettftext() [function.imagettftext]: Invalid font filename in D:\xampp\htdocs\test\class\pDraw.class.php on line 1023
我的问题出现在调用的类里面,,你们怎么看?
4楼的方法解决了,谢谢.
4楼正解,3KU!
4楼方法管用!

长URL(通常用关键字和跟踪参数都混乱)可以阻止访问者。 URL缩短脚本提供了解决方案,创建了简洁的链接,非常适合社交媒体和其他平台。 这些脚本对于单个网站很有价值

Laravel使用其直观的闪存方法简化了处理临时会话数据。这非常适合在您的应用程序中显示简短的消息,警报或通知。 默认情况下,数据仅针对后续请求: $请求 -

这是有关用Laravel后端构建React应用程序的系列的第二个也是最后一部分。在该系列的第一部分中,我们使用Laravel为基本的产品上市应用程序创建了一个RESTFUL API。在本教程中,我们将成为开发人员

Laravel 提供简洁的 HTTP 响应模拟语法,简化了 HTTP 交互测试。这种方法显着减少了代码冗余,同时使您的测试模拟更直观。 基本实现提供了多种响应类型快捷方式: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

PHP客户端URL(curl)扩展是开发人员的强大工具,可以与远程服务器和REST API无缝交互。通过利用Libcurl(备受尊敬的多协议文件传输库),PHP curl促进了有效的执行

您是否想为客户最紧迫的问题提供实时的即时解决方案? 实时聊天使您可以与客户进行实时对话,并立即解决他们的问题。它允许您为您的自定义提供更快的服务

2025年的PHP景观调查调查了当前的PHP发展趋势。 它探讨了框架用法,部署方法和挑战,旨在为开发人员和企业提供见解。 该调查预计现代PHP Versio的增长

在本文中,我们将在Laravel Web框架中探索通知系统。 Laravel中的通知系统使您可以通过不同渠道向用户发送通知。今天,我们将讨论您如何发送通知OV


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

安全考试浏览器
Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。

SublimeText3 Linux新版
SublimeText3 Linux最新版

SublimeText3汉化版
中文版,非常好用

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)