Imagick::setGravity()函数是PHP中的内置函数,用于为Imagick对象设置全局重力属性。
用法:
bool Imagick::setGravity( int $gravity )
参数:该函数接受单个参数$gravity,该参数具有int值。
重力常数列表如下:
imagick::GRAVITY_NORTHWEST(0)
imagick::GRAVITY_NORTH(1)
imagick::GRAVITY_NORTHEAST(2)
imagick::GRAVITY_WEST(3)
imagick::GRAVITY_CENTER(4)
imagick::GRAVITY_EAST(5)
imagick::GRAVITY_SOUTHWEST(6)
imagick::GRAVITY_SOUTH(7)
imagick::GRAVITY_SOUTHEAST(8)
返回值:该函数返回一个布尔值。
以下示例程序旨在说明PHP中的Imagick::setGravity()函数:
程序1:
// Create a new imagick object
$imagick = new Imagick();
// Set the Gravity to imagick::GRAVITY_NORTHWEST
$imagick->setGravity(0);
// Write the caption in a image
$imagick->newPseudoImage(800, 350, "caption:GeekforGeeks");
$imagick->floodfillPaintImage("blue", 1, "white", 1, 1, false);
// Show the output
$imagick->setformat('png');
header("Content-Type: image/png");
echo $imagick->getImageBlob();
?>
输出:
程序2:
// Create a new imagick object
$imagick = new Imagick();
// Set the Gravity to imagick::GRAVITY_SOUTH
$imagick->setGravity(7);
// Write the caption in a image
$imagick->newPseudoImage(800, 350, "caption:GeekforGeeks");
$imagick->floodfillPaintImage("blue", 1, "white", 1, 1, false);
// Show the output
$imagick->setformat('png');
header("Content-Type: image/png");
echo $imagick->getImageBlob();
?>
输出: