get('width'); $height = $this->get('height'); if ($width && $height) { return; } // Make sure that getting image size is supported. if ($this->mime !== 'image/svg+xml' || !\extension_loaded('simplexml')) { return; } // Make sure that the image exists. $path = $this->get('filepath'); if (!$path || !file_exists($path) || !filesize($path)) { return; } $xml = simplexml_load_string(file_get_contents($path)); $attr = $xml ? $xml->attributes() : null; if (!$attr instanceof \SimpleXMLElement) { return; } // Get the size from svg image. if ($attr->width && $attr->height) { $width = (string)$attr->width; $height = (string)$attr->height; } elseif ($attr->viewBox && \count($size = explode(' ', (string)$attr->viewBox)) === 4) { [,$width,$height,] = $size; } if ($width && $height) { $this->def('width', (int)$width); $this->def('height', (int)$height); } } }