Giter Site home page Giter Site logo

satori-php's Introduction

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.

satori-php's People

Contributors

choowx avatar dependabot[bot] avatar github-actions[bot] avatar berkaycubuk avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.