oscarotero / inline-svg
PHP库,用于在HTML中嵌入svg
v2.0.2
2019-06-18 12:22 UTC
Requires
- php: >=5.4.0
- ext-dom: *
This package is auto-updated.
Last update: 2024-09-18 23:31:38 UTC
README
PHP库,用于在HTML页面中嵌入svg图标,以便您可以使用CSS更改样式。为什么不使用图标字体?这里有一个svg与字体的比较
要求
- PHP 5.4+
- DOMDocument 扩展(PHP默认启用)
安装
此包可以通过Composer以oscarotero/inline-svg方式安装和自动加载。
$ composer require oscarotero/inline-svg
使用方法
use InlineSvg\Collection; use InlineSvg\Transformers\Cleaner; $icons = Collection::fromPath('path/to/svg/files'); //Add a cleaner transformer to remove ids $icons->addTransformer(new Cleaner()); //Insert the svg code of the file 'edit.svg': echo $icons->get('edit'); // <svg ... </svg> //Modify any attribute echo $icons->get('edit')->withAttribute('class', 'big-icon'); // <svg class="big-icon" .. </svg> //Make the svg accesible echo $icons->get('edit')->withA11y('The edit icon'); // <svg role="img" aria-labelledby="icon-edit-123-title"><title id="icon-edit-123-title">The edit icon</title> .. </svg>