PHP | imagickdraw getStrokeDashOffset()函数
ImagickDraw::getStrokeDashOffset()函数是PHP中的一个内置函数,用于获取虚线模式的偏移量以启动虚线。这个偏移量只不过是在开始由setStrokeDashArray()设置的破折号之前给出的间距。
句法:
float ImagickDraw::getStrokeDashOffset( void )
参数:此函数不接受任何参数。
返回值:此函数返回一个包含偏移量的浮点值。
异常:此函数在出错时抛出 ImagickException。
下面的程序说明了PHP中的ImagickDraw::getStrokeDashOffset()函数:
方案一:
getStrokeDashOffset();
echo $offset;
?>
输出:
0 // Which is the default value
方案二:
setStrokeDashOffset(50);
// Get the stroke dash offset
$offset = $draw->getStrokeDashOffset();
echo $offset;
?>
输出:
50
方案 3:
newImage(800, 250, 'black');
// Create a new ImagickDraw object
$draw = new ImagickDraw();
// Set the fill color
$draw->setFillColor('black');
// Set the color of stroke
$draw->setStrokeColor('white');
// Set the font size
$draw->setFontSize(15);
// Set the stroke dash array
$draw->setStrokeDashArray([20, 5, 19, 15, 5, 15]);
// Draw a rectangle
$draw->rectangle(100, 50, 225, 175);
// Annotate a text
$draw->annotation(50, 200, 'The strokeDashOffset here is '
. $draw->getStrokeDashOffset());
// Set the stroke dash offset
$draw->setStrokeDashOffset(20);
// Draw a rectangle
$draw->rectangle(500, 50, 625, 175);
// Get the stroke dash array
$strokeDashArray = $draw->getStrokeDashArray();
// Annotate a text
$draw->annotation(450, 200, 'The strokeDashOffset here is '
. $draw->getStrokeDashOffset());
// 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.getstrokedashoffset。 PHP