技术头条 - 一个快速在微博传播文章的方式     搜索本站
您现在的位置首页 --> PHP --> 利用php创建打印文字动画效果

利用php创建打印文字动画效果

浏览:2599次  出处信息

    利用php创建打印文字动画效果

    用php+imagick+imagemagick实现的代码如下,在ubuntu下如何安装使用imagick+imagemagick,可以看这篇文章,其他操作系统请google相关文章

    效果图片如下:

    anti-print

    源代码:

以下是代码片段:
< ?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);

建议继续学习:

  1. jQuery Color Animations颜色动画插件    (阅读:6917)
  2. css3-animation制作逐帧动画    (阅读:5155)
  3. 通过php+imagick 创建PDF图片预览    (阅读:3698)
  4. 解决jQuery动画在chrome下暴走的问题    (阅读:2984)
  5. jQuery中的动画    (阅读:2736)
  6. 闲谈CSS3动画    (阅读:2511)
  7. 完美实现GIF动画缩略图    (阅读:2396)
  8. CSS3 动画系列    (阅读:2281)
  9. 对比Imagick和Gmagick的像素迭代功能    (阅读:2201)
  10. 使用Jscex实现排序算法动画    (阅读:2212)
QQ技术交流群:445447336,欢迎加入!
扫一扫订阅我的微信号:IT技术博客大学习
© 2009 - 2024 by blogread.cn 微博:@IT技术博客大学习

京ICP备15002552号-1