【php开源代码栏目提醒】:网学会员,鉴于大家对php开源代码十分关注,论文会员在此为大家搜集整理了“fontout.php”一文,供大家参考学习!
<?php
$font = 'arial.ttf';
$imgfile=$_GET['imgfile'];
$ext=substr($imgfile,-3);
$ext=strtolower($ext);
//判断图片类型
if($ext=="jpg" || $ext=="jpe") $im=@imagecreatefromjpeg("$imgfile");
elseif ($ext=="gif") $im=@imagecreatefromgif("$imgfile");
else
{
echo "类型错误";
exit;
}
if (!$im)
{
//颜色设置
$im = ImageCreate (150, 40);
$bgc = ImageColorAllocate ($im, 255, 0, 255);
$tc = ImageColorAllocate ($im, 0, 0, 0);
ImageFilledRectangle ($im, 0, 0, 150, 30, $bgc);
//输出图像
ImageString($im, 1, 5, 5, "Error loading $imgfile", $tc);
return $im;
}
$x=imagesx($im);
$y=imagesy($im);
$fontsize=$x/20;
$fontsize=floor($fontsize);
if($fontsize<10) $fontsize=10;
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
imagettftext($im, $fontsize, 0, 12, $fontsize+8, $black, $font, $_GET['text']);
imagettftext($im, $fontsize, 0, 10, $fontsize+6, $white, $font, $_GET['text']);
if($ext=="gif")
{
header("Content-type: image/gif");
imageGIF($im);
}
else
{
header("Content-type: image/jpeg");
imagejpeg($im);
}
//清除资源
imagedetroy($im);
?>