Imagick 添加文字水印示例

原文来自

http://eclecticdjs.com/mike/tutorials/php/imagemagick/examples_04/setgravity.php

描述:

bool ImagickDraw::setGravity ( int $gravity )

设置文字水印的位置

参数:

Gravity参数只能是以下常量: imagick::GRAVITY_NORTHWEST //左下
imagick::GRAVITY_NORTH //左边居中
imagick::GRAVITY_EASNORTHT //左顶
imagick::GRAVITY_WEST     //底部居中
imagick::GRAVITY_CENTER    //居中
imagick::GRAVITY_EAST //顶部居中
imagick::GRAVITY_SOUTHWEST //对应右下角
imagick::GRAVITY_SOUTH    //右居中
imagick::GRAVITY_SOUTHEAST  //对应右上角

示例1
<?
$text
= "DJMike" ;
$font = "Bookman-DemiItalic" ;
$pointsize = 100 ;
$depth = 4 ;

#makeatransparentpallete
$pallete =new Imagick ;
$pallete -> newimage ( 450 , 105 , "transparent" );
#setpalletformattogif
$pallete -> setimageformat ( "gif" );

#makeadrawobjectwithsettings
$draw =new imagickdraw ();
$draw -> setgravity ( imagick :: GRAVITY_CENTER );
$draw -> setfont ( " $font " );
$draw -> setfontsize ( $pointsize );

#setfontcolorwhite
$draw -> setfillcolor ( "#ffffff" );
#offsetannotate
$pallete -> annotateImage ( $draw , $depth ,- $depth - 3 , 0 , $text );
$pallete -> annotateImage ( $draw ,- $depth ,- $depth - 3 , 0 , $text );

#setfontcolorblack
$draw -> setfillcolor ( "#000000" );
#offsetannotate
$pallete -> annotateImage ( $draw ,- $depth , $depth - 2 , 0 , $text );
$pallete -> annotateImage ( $draw , $depth , $depth - 3 , 0 , $text );

#setfontcolorblue
$draw -> setfillcolor ( "#0000ff" );
#centerannotateontopofoffsetannotates
$pallete -> annotateImage ( $draw , 0 , 0 , 0 , $text );

#blur
$pallete -> gaussianBlurImage ( 2 , 1.5 );

#outputtobrowser
$pallete -> setImageFormat ( "gif" );
header ( "Content-Type:image/gif" );
echo
$pallete ;
?>

示例2

<?
$text
= "DJMike" ;
$font = "lokicola.ttf" ;
$fontsize = 100 ;
$fontcolor = "#aa0000" ;
$glow_radius = 15 ;
#Threeglowcolors
$glow =array( "#ff0000" , "#ff8800" , "#ffff00" );

#movestextdown
$offset = 12 ;

#makeablackpallete
$pallete =new Imagick ;
$pallete -> newimage ( 375 , 140 , "#000000" );
#setpalletformattogif
$pallete -> setimageformat ( "gif" );

#makeadrawobjectwithsettings
$draw =new imagickdraw ();
$draw -> setgravity ( imagick :: GRAVITY_CENTER );
$draw -> setfont ( " $font " );
$draw -> setfontsize ( $fontsize );

#Loopthroughglowcolors
foreach( $glow as $var )
{
$draw -> setfillcolor ( " $var " );
$pallete -> annotateImage ( $draw , 0 , $offset , 0 , $text );
$pallete -> annotateImage ( $draw , 0 , $offset , 0 , $text );
$pallete -> BlurImage ( $glow_radius , $glow_radius );
}

#toplayer
$draw -> setfillcolor ( " $fontcolor " );
#centerannotateontopofoffsetannotates
$pallete -> annotateImage ( $draw , 0 , $offset , 0 , $text );

#outputtobrowser
$pallete -> setImageFormat ( "gif" );
header ( "Content-Type:image/gif" );
echo
$pallete ;
?>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值