利用php创建打印文字动画效果
用php+imagick+imagemagick实现的代码如下,在ubuntu下如何安装使用imagick+imagemagick,可以看这篇文章,其他操作系统请google相关文章
效果图片如下:
源代码:
以下是代码片段:
< ?php
/**
* 打印机打印效果
* @ param $text String 需要打印的文字
* @ param $color color|#16进制颜色
* @ param $fontsize int 字体大小
**/
function gif_print($text,$color=’red’,$fontsize = 40)
{
$ani = new Imagick();
$ani->setFormat(’gif’);
$textcolor = new ImagickPixel($color);
$bgcolor = new ImagickPixel(’white’);
//定义画笔
$draw = new ImagickDraw();
$draw->setFontSize($fontsize);
$draw->setFillColor($textcolor);
$draw->setGravity(imagick::GRAVITY_WEST);
//获取画笔写字的属性
$fontprop = $ani->queryFontMetrics($draw,$text);
$width = (int)$fontprop[’textWidth’] + 8;
$height = (int)$fontprop[’textHeight’] ;
//创建打印机的待机效果
$ani->newImage($width,$height,$bgcolor);
$draw->line(3,8,3,$height);
$ani->drawimage($draw);
$ani->setImageDelay(30);
$ani->newImage($width,$height,$bgcolor);
$ani->setImageDelay(30);
$ani->newImage($width,$height,$bgcolor);
$ani->drawimage($draw);
$ani->setImageDelay(30);
$textstrlen = strlen($text);
//创建打印机打印效果
for($i = 0;$i < = $textstrlen;$i++)
{
$single = substr($text,0,$i);
$ani->newImage($width,$height,$bgcolor);
$ani->setGravity(imagick::GRAVITY_WEST);
$ani->annotateImage($draw,0,0,0,$single);
$ani->setImageDelay(20);
}
header("Content-Type:image/gif");
echo $ani->getImagesBlob();
}
gif_print(’Welcome to Paitoubing.cn’,’blue’,30);