arnapou/pixelsvg

Library - Simple library to convert pixelated images to svg.

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

This package is auto-updated.

Last update: 2024-11-15 09:38:31 UTC


README

pipeline coverage

This library is a simple tool to convert pixelated images to SVG.

It optimises the svg file size by merging pixels in a single path.

Installation

composer require arnapou/pixelsvg

packagist 👉️ arnapou/pixelsvg

Renderer

The logic of the path rendering is in the Renderer you give to PixelSvg

RenderersExample 1Example 2Example 3Description
Original 0.7 KB 0.9 KB 0.3 KB
ByPixelRenderer 18.4 KB 7.6 KB 25.5 KBOne svg path by pixel.
ByColorRenderer 2.0 KB 1.8 KB 4.9 KBOne svg path by color.
ByColorLayeredRenderer 1.6 KB 1.5 KB 4.5 KBOne svg path by color + guessing overlapping layers to reduce the number of path points.
SplitAnimationRenderer 1.6 KB 1.5 KB 4.0 KBSplit the static pixels from the dynamic before calling the decorated renderer.
Color transforms injected in the rendererExample 1Example 2Example 3
ByColorRenderer + GrayColorTransform 2.0 KB 1.8 KB 4.9 KB
ByColorRenderer + UniqueColorTransform 0.3 KB 0.3 KB 0.5 KB

From code

$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);

⚠️ Prefer the use of Imagick for animated GIFs, because GD does not support it.

Php versions

DateRef8.38.2
26/11/20232.x, main×
05/08/20231.x×