Skip to content

Repository files navigation

atelier/rasterizer

Rasterize SVG documents to bitmaps through external rendering adapters (resvg, rsvg-convert). A typed PHP abstraction over a rasterizer binary; it does not render SVG in PHP itself.

Install

composer require atelier/rasterizer

Requires PHP 8.3+, symfony/process, psr/log, and one rasterizer binary on the host (resvg or rsvg-convert).

# macOS
brew install resvg

# Debian / Ubuntu
apt install librsvg2-bin

See Installation for other platforms, package-source links, and binary licenses.

Example

use Atelier\Rasterizer\Bitmap\BitmapOptions;
use Atelier\Rasterizer\Rasterizer;

$rasterizer = Rasterizer::create();

$bitmap = $rasterizer->rasterize($svg, new BitmapOptions(
    width: 1200,
    height: 630,
    keepAspectRatio: true,
));

$bitmap->save('card.png');

$svg is a markup string, any \Stringable (such as an Atelier\Svg\Svg document), or an SvgInput built from a file or stream. keepAspectRatio is enabled by default, so giving both width and height fits the SVG inside that box where the selected adapter supports it.

Rasterizer::create() picks the first available adapter in package order (resvg, then rsvg-convert). For reproducible production output, you can also select an adapter explicitly:

$rasterizer = Rasterizer::resvg();
$rasterizer = Rasterizer::rsvgConvert();

Documentation

License

MIT

About

Rasterize SVG documents to bitmaps through resvg and rsvg-convert adapters.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages