Merge pull request #99 from cosmocode/svg-dimensions
Improve SVG sizing
This commit is contained in:
commit
4c08b3b7b8
1 changed files with 8 additions and 3 deletions
11
svg.php
11
svg.php
|
@ -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>";
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue