插件19:GIF文本

<?php // Plug-in 19: Gif Text

// This is an executable example with additional code supplied
// To obtain just the plug-ins please click on the Download link
// This example requires a TTF font file named oldenglish.ttf
// to be in the same directory

PIPHP_GifText("font1.gif", "Old English Font", "oldenglish.ttf",
   26, "ff0000", "ffffff", 1, "444444");
PIPHP_GifText("font2.gif", "Old English Font", "oldenglish.ttf",
   36, "ff0000", "ffffff", 2, "444444");
PIPHP_GifText("font3.gif", "Old English Font", "oldenglish.ttf",
   46, "ff0000", "ffffff", 3, "444444");
PIPHP_GifText("font4.gif", "Old English Font", "oldenglish.ttf",
   56, "ff0000", "ffffff", 4, "444444");

echo "<img src='font1.gif'>";
echo "<img src='font2.gif'>";
echo "<img src='font3.gif'>";
echo "<img src='font4.gif'>";

function PIPHP_GifText($file, $text, $font, $size, $fore, $back,
   $shadow, $shadowcolor)
{
   // Plug-in 19: Gif Text
   //
   // This plug-in accepts text input and then turns it into
   // a gif image. Various font sizes and effects are available
   // The arguments required are:
   //
   //    $file:        The path and file to save the finished gif
   //    $text:        The text to display
   //    $font:        Filename of a TTF font file
   //    $size:        Font size to use
   //    $fore:        The foreground color
   //    $back:        The background color
   //    $shadow:      0 = None, 1 or more = The offset to use
   //    $shadowcolor: The shadow color (if selected)

   $bound  = imagettfbbox($size, 0, $font, $text);
   $width  = $bound[2] + $bound[0] + 6 + $shadow;
   $height = abs($bound[1]) + abs($bound[7]) + 5 + $shadow;
   $image  = imagecreatetruecolor($width, $height);
   $bgcol  = PIPHP_GD_FN1($image, $back);
   $fgcol  = PIPHP_GD_FN1($image, $fore);
   $shcol  = PIPHP_GD_FN1($image, $shadowcolor);
   imagefilledrectangle($image, 0, 0, $width, $height, $bgcol);
   
   if ($shadow > 0)
   {
      imagettftext($image, $size, 0, $shadow + 2,
      abs($bound[5]) + $shadow + 2, $shcol, $font, $text);
   
      for ($j = 0 ; $j < 5 ; ++$j)
         imagefilter($image, IMG_FILTER_GAUSSIAN_BLUR);
   }
   
   imagettftext($image, $size, 0, 2, abs($bound[5]) + 2, $fgcol,
      $font, $text);
   imagegif($image, $file);
}

function PIPHP_GD_FN1($image, $color)
{
   return imagecolorallocate($image,
      hexdec(substr($color, 0, 2)),
      hexdec(substr($color, 2, 2)),
      hexdec(substr($color, 4, 2)));
}

?>
插件说明:

本插件需要一个用来保存GIF图像的文件名,一个文本和文本的字体,颜色,字体大小以及阴影等详细信息。具体如下:

$file GIF图像的保存路径和文件名。

$text 需要处理的文本。

$font TrueType字体的路径和文件名。

$size 字体大小。

$fore 前景颜色,用十六进制表示(如000000)。

$back 背景颜色,用十六进制表示(如FFFFFF)。

$shadow 用像素个数表示文字的阴影效果(0表示无阴影)。

$shadowcolor 阴影颜色(如444444)。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值