使用php画饼状图 imagefontheight函数,PHP imagefontheight 用法 手册 | 示例代码

This library function is very useful for variable-sized images that only contain text, like this function that I use to output error messages that accumulate and cause a fatal error in my thumbnailer:

// initialization$font_size=2;$text_width=imagefontwidth($font_size);$text_height=imagefontheight($font_size);$width=0;// the height of the image will be the number of items in $error$height=count($error);// this gets the length of the longest string, in characters to determine

// the width of the output imagefor($x=0;$x

if(strlen($error[$x]) >$width) {$width=strlen($error[$x]);

}

}// next we turn the height and width into pixel values$width=$width*$text_width;$height=$height*$text_height;// create image with dimensions to fit text, plus two extra rows and

// two extra columns for border$im=imagecreatetruecolor($width+ (2*$text_width),$height+ (2*$text_height) );

if($im) {// image creation success$text_color=imagecolorallocate($im,233,14,91);// this loop outputs the error message to the imagefor($x=0;$x

}// now, render your image using your favorite image* function

// (imagejpeg, for instance)out($im, array(),$error);

} else {// image creation failed, so just dump the array along with extra error$error[] ="Is GD Installed?";

die(var_dump($error));

}

}?>

The function expects an array of error messages to be passed in, and then outputs an image containing the contents of the array.  This is especially useful if your code is contained in an html page that will display rexes if the images do not render correctly.

This function displays the array in image form with index 0 at the top, and the highest index at the bottom.

You have to write out() yourself though, see imagejpeg, imagepng, etc for good ideas on how to write a decent output function.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值