meyfa / php-svg

Vector graphics (SVG) library for PHP
https://packagist.org/packages/meyfa/php-svg
MIT License
509 stars 91 forks source link

Error if font-size not set explicitly #195

Closed meyfa closed 1 year ago

meyfa commented 1 year ago

The following code leads to an error:

SVG::addFont(__DIR__ . '/font/Roboto-Bold.ttf');
$svg = new SVG(100, 100);

$text = new SVGText('foo', 50, 50);
$svg->getDocument()->addChild($text);

header('Content-Type: image/png');
imagepng($larvatar->toRasterImage(100, 100));

Error:

Fatal error:
Uncaught TypeError:
Argument 1 passed to SVG\Rasterization\Transform\Transform::resize() must be of the type float, null given,
called in php-svg\src\Rasterization\Renderers\TextRenderer.php on line 31
and defined in php-svg\src\Rasterization\Transform\Transform.php on line 94

Setting the font size explicitly fixes the problem:

$text->setStyle('font-size', '12pt');

There should be a default font size used, in case none is explicitly defined, to avoid this error.