Issue
I'm trying to draw a dashed line using PHP Imagick. This code produces a solid line:
$line = new ImagickDraw();
$line->setStrokeWidth(3);
$line->setStrokeDashArray([10, 10]);
$line->line(0, 0, 100, 100);
setStrokeDashArray()
seems to work for outlines on ImagickDraw::rectangle()
but not ImagickDraw::line()
drawings. Is there any way to draw simple dashed lines?
Solution
To get a nice dashed line without a solid line inside of it, set the fill color to opacity of zero (the actual color choice doesn't matter so long as the opacity value is a 0
), and then don't forget to set a stroke color.
A working example (with an added debugging to browser dump):
$line = new ImagickDraw();
$line->setStrokeColor('rgb(0, 0, 0)');
$line->setFillColor('rgba(255, 255, 255, 0)');
$line->setStrokeWidth(3);
$line->setStrokeDashArray([10, 10]);
$line->line(0, 0, 100, 100);
// for debugging, output to browser:
$image = new Imagick();
$image->newImage(200, 200, 'rgb(230, 230, 230)');
$image->setImageFormat("png");
$image->drawImage($line);
header("Content-Type: image/png");
echo $image->getImageBlob();
exit;
Debug output result:
Answered By - IncredibleHat Answer Checked By - Robin (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.