choowx/satori-php

Run Satori — enlightened library to convert HTML and CSS to SVG, using PHP

Fund package maintenance!
choowx

v0.2.2 2023-06-08 10:44 UTC

README

Satori

Run Satori — enlightened library to convert HTML and CSS to SVG, using PHP

Latest Version on Packagist Tests Total Downloads

Satori — enlightened library to convert HTML and CSS to SVG.

This package makes it easy to run Satori using PHP.

Installation

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

Usage

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

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.