arnapou / pixelsvg
Library - Simple library to convert pixelated images to svg.
v2.0
2023-11-26 10:47 UTC
Requires
- php: ~8.3.0
- arnapou/ensure: ^2.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.40
- phpstan/phpstan: ^1.10
- phpunit/php-code-coverage: ^10.1
- phpunit/phpunit: ^10.4
- vimeo/psalm: ^5.16
README
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
Renderers | Example 1 | Example 2 | Example 3 | Description |
---|---|---|---|---|
Original | ![]() | ![]() | ![]() | |
ByPixelRenderer | One svg path by pixel. | |||
ByColorRenderer | One svg path by color. | |||
ByColorLayeredRenderer | One svg path by color + guessing overlapping layers to reduce the number of path points. | |||
SplitAnimationRenderer | Split the static pixels from the dynamic before calling the decorated renderer. |
Color transforms injected in the renderer | Example 1 | Example 2 | Example 3 |
---|---|---|---|
ByColorRenderer + GrayColorTransform | |||
ByColorRenderer + UniqueColorTransform |
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
Start | Tag, Branch | Php |
---|---|---|
26/11/2023 | 2.x, main | 8.3 |
05/08/2023 | 1.x | 8.2 |