diff --git a/system/src/Grav/Common/Page/Medium/MediumFactory.php b/system/src/Grav/Common/Page/Medium/MediumFactory.php index 620446b70..913f198f1 100644 --- a/system/src/Grav/Common/Page/Medium/MediumFactory.php +++ b/system/src/Grav/Common/Page/Medium/MediumFactory.php @@ -159,8 +159,9 @@ class MediumFactory return new ImageMedium($items, $blueprint); case 'thumbnail': return new ThumbnailImageMedium($items, $blueprint); - case 'animated': case 'vector': + return new VectorImageMedium($items, $blueprint); + case 'animated': return new StaticImageMedium($items, $blueprint); case 'video': return new VideoMedium($items, $blueprint); diff --git a/system/src/Grav/Common/Page/Medium/VectorImageMedium.php b/system/src/Grav/Common/Page/Medium/VectorImageMedium.php new file mode 100644 index 000000000..b43c38214 --- /dev/null +++ b/system/src/Grav/Common/Page/Medium/VectorImageMedium.php @@ -0,0 +1,63 @@ +get('filepath'); + if (!$path || !file_exists($path) || !filesize($path)) { + return; + } + + $xml = simplexml_load_string(file_get_contents($path)); + $attr = $xml->attributes(); + + if (!$attr instanceof \SimpleXMLElement) { + return; + } + + if ($attr->width > 0 && $attr->height > 0) { + $width = (int)$attr->width; + $height = (int)$attr->height; + } elseif ($attr->viewBox && count($size = explode(' ', $attr->viewBox)) === 4) { + $width = (int)$size[2]; + $height = (int)$size[3]; + } + + if ($width && $height) { + $this->def('width', $width); + $this->def('height', $height); + } + } +}