原文来自
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
;
?>