Merge pull request #99 from cosmocode/svg-dimensions

Improve SVG sizing
This commit is contained in:
Andreas Gohr 2023-03-02 16:50:24 +01:00 committed by GitHub
commit 4c08b3b7b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

11
svg.php
View file

@ -175,11 +175,16 @@ class SVG {
$xml = simplexml_load_file($file, SvgNode::class);
$def = hsc((string) $xml->path['d']);
$w = hsc($xml['width']);
$h = hsc($xml['height']);
$w = hsc($xml['width'] ?? '100%');
$h = hsc($xml['height'] ?? '100%');
$v = hsc($xml['viewBox']);
return "<svg width=\"$w\" height=\"$h\" viewBox=\"$v\"><path d=\"$def\" /></svg>";
// if viewbox is not defined, construct it from width and height, if available
if (empty($v) && !empty($w) && !empty($h)) {
$v = hsc("0 0 $w $h");
}
return "<svg viewBox=\"$v\"><path d=\"$def\" /></svg>";
}
/**