arnapou / pixelsvg
Library - Simple library to convert pixelated images to svg.
v2.3.0
2024-11-25 09:18 UTC
Requires
- php: ~8.3.0 || ~8.4.0
- arnapou/ensure: ^2.3
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.52
- phpstan/extension-installer: ^1.3
- phpstan/phpstan: ^2.0
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- phpstan/phpstan-strict-rules: ^2.0
- phpunit/php-code-coverage: ^11.0
- phpunit/phpunit: ^11.0
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.
Php versions
Date | Ref | 8.4 | 8.3 | 8.2 |
---|---|---|---|---|
25/11/2024 | 2.3.x, main | × | × | |
26/11/2023 | 2.0 - 2.2 | × | ||
05/08/2023 | 1.x | × |