arnapou/svg
最新稳定版本:v1.1.0
Composer 安装命令:
composer require arnapou/svg
包简介
Library - Help to draw svg images.
README 文档
README
This library is a simple tool to generate SVG images.
It depends on arnapou/geometry for basic geometric shapes and transformations.
Installation
composer require arnapou/svg
packagist 👉️ arnapou/svg
Examples
basic.php
use Arnapou\Geometry\Element\Circle;
use Arnapou\Geometry\Element\Point;
use Arnapou\Geometry\Turtle;
use Arnapou\Svg\Color\NamedColor;
use Arnapou\Svg\SvgAttributeList\Fill;
use Arnapou\Svg\SvgAttributeList\Stroke;
use Arnapou\Svg\SvgAttributeList\SvgAttributes;
use Arnapou\Svg\SvgImage;
$style = new SvgAttributes(
Fill::transparent(),
new Stroke(NamedColor::blue, width: 5.0),
);
$image = new SvgImage(200, 100);
$image->children->add(new Circle(new Point(50, 50), radius: 20), $style);
$image->children->add(
Turtle::start(0, 0)
->forward(80)->turn(270, 10)
->forward(30)->turn(270, 10)
->forward(80)->turn(270, 10)
->forward(30)->turn(270, 10)
->getPath()
->rotate(M_PI / 12, new Point(0, 0))
->translate(90, 45),
$style,
);
$image->write(__DIR__ . '/basic.svg');
polyline.php
use Arnapou\Geometry\Element\Point;
use Arnapou\Geometry\Element\Polyline;
use Arnapou\Svg\Color\NamedColor;
use Arnapou\Svg\SvgAttribute\StrokeLineCap;
use Arnapou\Svg\SvgAttribute\StrokeLineJoin;
use Arnapou\Svg\SvgAttributeList\Fill;
use Arnapou\Svg\SvgAttributeList\Stroke;
use Arnapou\Svg\SvgImage;
$polyline = new Polyline(
[
new Point(0, 0),
new Point(10, 30),
new Point(20, 20),
new Point(35, 20),
new Point(50, 40),
new Point(40, 5),
new Point(20, 10),
],
closed: true,
);
$image = new SvgImage(200, 100);
$image->children->add(
$polyline,
Fill::transparent(),
new Stroke(NamedColor::red),
);
$image->children->add(
$polyline
->toPolyline(closed: false)
->rotate(M_PI_4, new Point())
->translate(100, 20),
new Fill(NamedColor::gray, opacity: 0.5),
new Stroke(NamedColor::darkblue, width: 5.0),
StrokeLineJoin::bevel,
StrokeLineCap::round,
);
$image->flipVertical()->write(__DIR__ . '/polyline.svg');
Php versions
| Date | Ref | 8.5 | 8.4 | 8.3 |
|---|---|---|---|---|
| 25/10/2025 | 1.1.x, main | × | × | × |
| 29/01/2025 | 1.0.x | × | × |
统计信息
- 总下载量: 24
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-02-13