Answer the question
In order to leave comments, you need to log in
How to draw an arc for an SVG file using PHP?
To draw simple objects from lines and circles / ellipses, I use the php-svg
library.
Now I have encountered a problem with drawing an arc (part of a circle).
For example, you need to draw half a circle, or a quarter (knowing the radius of the circle).
Now, to draw lines using the library, I use the following code:
$image = new SVG(10mm','10mm');
$doc = $image->getDocument();
$square = new SVGLine('0mm', '0mm', '5mm', '5mm'); // x0 y0 x1 y1
$square->setStyle('stroke', '#FF0000'); //цвет
$doc->addChild($square);
header('Content-Type: image/svg+xml');
echo $image;
Answer the question
In order to leave comments, you need to log in
The easiest way to draw an arc is through the path element.
$image = new SVG('100mm','100mm');
$doc = $image->getDocument();
$square = new SVGLine('0mm', '0mm', '55mm', '55mm'); // x0 y0 x1 y1
$square->setStyle('stroke', '#FF0000'); //цвет
$doc->addChild($square);
$arc = new SVGPath('m 40,40 A 30,30,0,0,1,150,150');
$arc->setStyle('stroke', '#FF0000');
$doc->addChild($arc);
header('Content-Type: image/svg+xml');
echo $image;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question