Library - Simple library to convert pixelated images to svg.

v2.0 2023-11-26 10:47 UTC

This package is auto-updated.

Last update: 2023-11-26 10:47:19 UTC


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.


composer require arnapou/pixelsvg

packagist 👉️ arnapou/pixelsvg


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.

Changelog versions

StartTag, BranchPhp
26/11/20232.x, main8.3