PHP | ImagickDraw getGravity()函数
ImagickDraw::getGravity()函数是PHP中的一个内置函数,用于获取文本注释时使用的文本放置重力。
句法:
int ImagickDraw::getGravity( void )
参数:此函数不接受任何参数。
返回值:此函数返回与 GRAVITY 常量之一对应的整数值,如果未设置,则返回 0。
重力常数列表如下:
- 想像::GRAVITY_NORTHWEST (1)
- imagick::GRAVITY_NORTH (2)
- imagick::GRAVITY_NORTHEAST (3)
- imagick::GRAVITY_WEST (4)
- imagick::重力中心 (5)
- imagick::GRAVITY_EAST (6)
- 想像::GRAVITY_SOUTHWEST (7)
- imagick::GRAVITY_SOUTH (8)
- imagick::GRAVITY_SOUTHEAST (9)
下面的程序说明了PHP中的ImagickDraw::getGravity()函数:
方案一:
getGravity();
echo $Gravity;
?>
输出:
0 // Which is the default value.
方案二:
setGravity(8);
// Get the font Gravity
$Gravity = $draw->getGravity();
echo $Gravity;
?>
输出:
8
方案 3:
newImage(800, 250, 'black');
// Create a new ImagickDraw object
$draw = new ImagickDraw();
// Set the fill color
$draw->setFillColor('cyan');
// Set the font size
$draw->setFontSize(20);
// Annotate a text to (50, 100)
$draw->annotation(50, 100,
'The gravity here is ' . $draw->getGravity());
// Set the gravity
$draw->setGravity(3);
// Annotate a text to (50, 100)
$draw->annotation(50, 100,
'The gravity here is ' . $draw->getGravity());
// Render the draw commands
$imagick->drawImage($draw);
// Show the output
$imagick->setImageFormat('png');
header("Content-Type: image/png");
echo $imagick->getImageBlob();
?>
输出:
参考: https://www. PHP.net/manual/en/imagickdraw.getgravity。 PHP