arnapou/pixelsvg

库 - 将像素化图像转换为 SVG 的简单库。

v2.2 2024-04-14 15:55 UTC

This package is auto-updated.

Last update: 2024-09-08 14:56:39 UTC


README

pipeline coverage

此库是一个将像素化图像转换为 SVG 的简单工具。

它通过合并单一路径中的像素来优化 SVG 文件大小。

安装

composer require arnapou/pixelsvg

packagist 👉️ arnapou/pixelsvg

渲染器

路径渲染的逻辑在您提供给 PixelSvgRenderer 中。

渲染器示例 1示例 2示例 3描述
原始 0.7 KB 0.9 KB 0.3 KB
ByPixelRenderer 18.4 KB 7.6 KB 25.5 KB每个像素一个 SVG 路径。
ByColorRenderer 2.0 KB 1.8 KB 4.9 KB每个颜色一个 SVG 路径。
ByColorLayeredRenderer 1.6 KB 1.5 KB 4.5 KB一个 SVG 路径通过颜色 + 猜测重叠层以减少路径点数。
SplitAnimationRenderer 1.6 KB 1.5 KB 4.0 KB在调用装饰渲染器之前,将静态像素与动态像素分开。
在渲染器中注入颜色转换示例 1示例 2示例 3
ByColorRenderer + GrayColorTransform 2.0 KB 1.8 KB 4.9 KB
ByColorRenderer + UniqueColorTransform 0.3 KB 0.3 KB 0.5 KB

从代码中

$filename = '/some/file/to/convert.gif';

$renderer = new \Arnapou\PixelSvg\Renderer\ByColorRenderer();
$pixelSvg = new \Arnapou\PixelSvg\PixelSvg($renderer);

$reader = new \Arnapou\PixelSvg\ImageReader\ImagickReader::fromFilename($filename);
$svgContent = $pixelSvg->render($reader);

⚠️ 对于动画 GIF,首选使用 Imagick,因为 GD 不支持它。

PHP 版本

日期参考8.38.2
26/11/20232.x, main×
05/08/20231.x×