Satori — enlightened library to convert HTML and CSS to SVG.
This package makes it easy to run Satori using PHP.
You can install the package via composer:
composer require choowx/satori-php
This package relies on the satori
and html-react-parser
js packages being available on your system. In most cases you can accomplish this by issues these commands in your project.
npm install satori
npm install html-react-parser
use Choowx\Satori\Satori;
$svg = Satori::html('<div style="color: black">hello, world</div>')->convert();
// $svg = '<svg width="1200" height="630" viewBox="0 0 1200 630" xmlns="http://www.w3.org/2000/svg"><path fill="black"...
The width and height of the svg can be configured:
use Choowx\Satori\Satori;
$svg = Satori::html('<div style="color: black">hello, world</div>')
->width(600)
->height(315)
->convert();
// $svg = '<svg width="600" height="315" viewBox="0 0 600 315"...
Using custom fonts available in the file system:
Satori currently supports three font formats: TTF, OTF and WOFF. Note that WOFF2 is not supported at the moment.
use Choowx\Satori\Font;
use Choowx\Satori\Satori;
$svg = Satori::html('<div style="color: black">hello, world</div>')
->withFonts([
Font::path('/path/to/Roboto-Regular.ttf')
->name('Roboto')
->weight(400)
->style('regular'),
Font::path('/path/to/Roboto-Bold.ttf')
->name('Roboto')
->weight(700)
->style('bold'),
])
->convert();
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.