mober / phpsvg
使用OO PHP编辑和创建SVG文档
v5.0.1
2023-11-28 22:02 UTC
Requires
- php: 8.0 - 8.3
- ext-dom: *
- ext-fileinfo: *
- ext-simplexml: *
Requires (Dev)
- squizlabs/php_codesniffer: ^3.5 | ^4.0
- vimeo/psalm: ^5.15
Suggests
- ext-imagick: Export images using Imagick
- ext-zlib: Read/write compressed files
This package is auto-updated.
Last update: 2024-09-28 23:43:27 UTC
README
使用PHP编辑和创建SVG文档。该库是基于mewebstudio/phpsvg
的分支,最后更新于2013年。
功能
- 打开和编辑SVG和SVGZ(GZipped)
- 生成缩略图或导出为PNG、JPG、GIF、PS、EPS、PDF
- 支持嵌入式或链接的图像
- 严格的类型声明,即
declare(strict_types=1);
安装
- 4.x版本支持PHP 8.0及更高版本,因为某些功能(如流畅方法)需要早期版本中不可用的语言特性。
- 3.x版本不再维护,支持PHP 7.1至8.0。
使用composer安装
composer require mober/phpsvg
示例
$svg = new SVGDocument(); $gradient = new SVGLinearGradient([ // Set style using fluent methods (new SVGStop(0))->setColor('blue')->setOpacity(1), (new SVGStop(0.8))->setColor('cyan')->setOpacity(0.5), ]); $svg->addDefs($gradient); $svg->addShape( new SVGRect(10, 20, '100', '200', (new SVGStyle())->setFill($gradient)) ); $radial = new SVGRadialGradient([ // Set style as string new SVGStop(0, 'stop-color:yellow;stop-opacity:1'), new SVGStop(0.7, 'stop-color:green;stop-opacity:1'), ]); $svg->addDefs($radial); $svg->addShape( new SVGCircle(250, 120, 100, (new SVGStyle())->setFill($radial)) ); $svg->writeXML('demo.svg', humanReadable: true);