承接 gymmed/svg-parser 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

gymmed/svg-parser

最新稳定版本:v0.1

Composer 安装命令:

composer require gymmed/svg-parser

包简介

Includes css document styles to svg without editing original svg document.

README 文档

README

Svg Parser PHP


Applying styles to svg.

Applies CSS document styles to an SVG without modifying the original SVG file. It also parses CSS variables and inserts their values directly into CSS selectors styles, as it is intendent for broader use than just for browser rendering.

Installation

You can install the package via composer:

composer require gymmed/svg-parser-php

Use Case

Dompdf or laravel wrapper laravel-dompdf don't support direct SVG import or requires the inclusion of external SVG files. This library provides a way to attach CSS documents to SVG files without needing to directly modify the SVG.

If you stumble upon the same problem, I highly recommend using imagick or rasterize-svg to convert the SVG to PNG and include it in the PDF. This way, you reduce the chances of the styles being rendered incorrectly by Dompdf and won't need two different CSS documents or two SVG files.

Usage

use GymMed\SvgParser;

//provide full path
$svgPath = realpath(__DIR__ . "./assets/example.svg");
$cssPath = realpath(__DIR__ . "./assets/css/index.css");

$svgWithCSS = SvgParser::formatSvgFromPath($svgPath, [$cssPath]);

or use SVG content:

use GymMed\SvgParser;

//provide full path
$svgPath = realpath(__DIR__ . "./assets/example.svg");
$cssPath = realpath(__DIR__ . "./assets/css/index.css");
$svg = file_get_contents($svgPath);

$svgWithCSS = SvgParser::formatSvg($svg, [$cssPath]);

If you want to write simple CSS and apply it inside SVG:

use GymMed\SvgParser;

//provide full path
$svgPath = realpath(__DIR__ . "./assets/example.svg");
$svg = file_get_contents($svgPath);

$svgWithCSS = SvgParser::getParsedCSSToSvg($svg, ".circle { background-color: red; border-radius: 50% }");

If you want to provide only full path instead of SVG itself:

use GymMed\SvgParser;

//provide full path
$svgPath = realpath(__DIR__ . "./assets/example.svg");

$svgWithCSS = SvgParser::getParsedCSSToSvgFromPath($svgPath, ".circle { background-color: red; border-radius: 50% }");

统计信息

  • 总下载量: 10
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-09-15

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固