ImagickDraw::setGravity()函數是PHP中的內置函數,用於在注釋文本時設置文本放置的重力。
用法:
bool ImagickDraw::setGravity( $gravity )
參數:該函數接受單個參數$gravity,該參數用於將重力值保持為GRAVITY_常數。
重力常數列表如下:
- imagick::GRAVITY_NORTHWEST(整數)
- imagick::GRAVITY_NORTH(整數)
- imagick::GRAVITY_NORTHEAST(整數)
- imagick::GRAVITY_WEST(整數)
- imagick::GRAVITY_CENTER(整數)
- imagick::GRAVITY_EAST(整數)
- imagick::GRAVITY_SOUTHWEST(整數)
- imagick::GRAVITY_SOUTH(整數)
- imagick::GRAVITY_SOUTHEAST(整數)
返回值:該函數不返回任何值。
以下示例程序旨在說明PHP中的ImagickDraw::setGravity()函數:
程序1:
<?php
// Create an ImagickDraw object
$draw = new ImagickDraw();
// Set the image filled color
$draw->setFillColor('Green');
// Set the Font Size
$draw->setFontSize(30);
// Set the Gravity Position
$draw->setGravity(5);
// Set the font family
$draw->setFontFamily('Ani');
// Set the text to be added
$draw->annotation(30, 40, "GeeksForGeeks");
// Create new Imagick object
$imagick = new Imagick();'
// Set the image dimension
$imagick->newImage(300, 150, 'white');
// Set the image format
$imagick->setImageFormat("png");
// Draw the image
$imagick->drawImage($draw);
header("Content-Type: image/png");
// Display the image
echo $imagick->getImageBlob();
?>
輸出:
程序2:
<?php
// Create an ImagickDraw object
$draw = new ImagickDraw();
// Set the image filled color
$draw->setFillColor('green');
// Set the font size
$draw->setFontSize(60);
// Set the Gravity Position
$draw->setGravity(2);
// Set the text decoration
$draw->setTextDecoration(4);
// Set the text to be added
$draw->annotation(50, 75, "GeeksForGeeks");
// Create new Imagick object
$imagick = new Imagick();
// Set the image dimensions
$imagick->newImage(600, 160, 'white');
// Set the image format
$imagick->setImageFormat("png");
// Draw the image
$imagick->drawImage($draw);
header("Content-Type: image/png");
// Display the image
echo $imagick->getImageBlob();
?>
輸出:
參考: http://php.net/manual/en/imagickdraw.setgravity.php
相關用法
- PHP Imagick setGravity()用法及代碼示例
- PHP ImagickDraw pop()用法及代碼示例
- PHP ImagickDraw arc()用法及代碼示例
- PHP ImagickDraw setStrokeColor()用法及代碼示例
- PHP ImagickDraw rotate()用法及代碼示例
- PHP ImagickDraw pathCurveToAbsolute()用法及代碼示例
- PHP ImagickDraw pathClose()用法及代碼示例
- PHP ImagickDraw popClipPath()用法及代碼示例
- PHP ImagickDraw setStrokeLineJoin()用法及代碼示例
- PHP ImagickDraw skewY()用法及代碼示例
- PHP ImagickDraw pathCurveToSmoothAbsolute()用法及代碼示例
- PHP ImagickDraw getFillColor()用法及代碼示例
- PHP ImagickDraw annotation()用法及代碼示例
- PHP ImagickDraw setStrokeAlpha()用法及代碼示例
- PHP ImagickDraw setTextAlignment()用法及代碼示例
注:本文由純淨天空篩選整理自sarthak_ishu11大神的英文原創作品 PHP | ImagickDraw setGravity() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。