wp/lib/blobfolio/wp/bm/svg/svg_fallback.php
public static function get_dimensions($svg = '') {
		if (false === ($svg = static::import($svg))) {
			return false;
		}

		try {

			// Prefer SimpleXML.
			if (\class_exists('SimpleXMLElement')) {
				\libxml_use_internal_errors(true);
				\libxml_disable_entity_loader(true);

				$svg = new SimpleXMLElement($svg);

				$width = isset($svg['width']) ? (string) $svg['width'] : null;
				$height = isset($svg['height']) ? (string) $svg['height'] : null;
				$viewbox = isset($svg['viewBox']) ? (string) $svg['viewBox'] : null;
			} // Otherwise try to parse it out.
			else {
				$width = $height = $viewbox = null;

				\preg_match('/<svg\s?([^>]*)>/i', $svg, $match);
				if (\count($match) >= 2) {
					\preg_match_all('/(width|height|viewBox)\s*=\s*(([\d\.]+)|("|\')([^"\']+)("|\'))/i', $match[1], $matches);
					if (\count($matches[0])) {
						foreach ($matches[1] as $k=>$tag) {
							$tag = \strtolower($tag);
							$$tag = \strlen($matches[3][$k]) ? $matches[3][$k] : $matches[5][$k];
						}
					}
				}
			}

			// Prefer the viewbox as it is more likely to be numeric,
			// and also more likely to reflect the real dimensions.
			if (! \is_null($viewbox)) {
				$viewbox = \trim(\preg_replace('/\s+/', ' ', $viewbox));
				$viewbox = \explode(' ', $viewbox);
				if (\count($viewbox) === 4) {
					$viewbox[2] = (float) $viewbox[2];
					$viewbox[3] = (float) $viewbox[3];

					if ($viewbox[2] > 0 && $viewbox[3] > 0) {
						return array(
							'width'=>$viewbox[2],
							'height'=>$viewbox[3],
						);
					}
				}
			}

			// Otherwise maybe the width and height are good?
			if (\is_numeric($width) && \is_numeric($height)) {
				$width = (float) $width;
				$height = (float) $height;

				if ($width > 0 && $height > 0) {
					return array(
						'width'=>$width,
						'height'=>$height,
					);
				}
			}
		} catch (\Throwable $e) {
			return false;
		} catch (\Exception $e) {
			return false;
		}

		return false;
	}
public static function get_dimensions($svg = '') {
		if (false === ($svg = static::import($svg))) {
			return false;
		}

		try {

			// Prefer SimpleXML.
			if (\class_exists('SimpleXMLElement')) {
				\libxml_use_internal_errors(true);
				\libxml_disable_entity_loader(true);

				$svg = new SimpleXMLElement($svg);

				$width = isset($svg['width']) ? (string) $svg['width'] : null;
				$height = isset($svg['height']) ? (string) $svg['height'] : null;
				$viewbox = isset($svg['viewBox']) ? (string) $svg['viewBox'] : null;
			} // Otherwise try to parse it out.
			else {
				$width = $height = $viewbox = null;

				\preg_match('/<svg\s?([^>]*)>/i', $svg, $match);
				if (\count($match) >= 2) {
					\preg_match_all('/(width|height|viewBox)\s*=\s*(([\d\.]+)|("|\')([^"\']+)("|\'))/i', $match[1], $matches);
					if (\count($matches[0])) {
						foreach ($matches[1] as $k=>$tag) {
							$tag = \strtolower($tag);
							$$tag = \strlen($matches[3][$k]) ? $matches[3][$k] : $matches[5][$k];
						}
					}
				}
			}

			// Prefer the viewbox as it is more likely to be numeric,
			// and also more likely to reflect the real dimensions.
			if (! \is_null($viewbox)) {
				$viewbox = \trim(\preg_replace('/\s+/', ' ', $viewbox));
				$viewbox = \explode(' ', $viewbox);
				if (\count($viewbox) === 4) {
					$viewbox[2] = (float) $viewbox[2];
					$viewbox[3] = (float) $viewbox[3];

					if ($viewbox[2] > 0 && $viewbox[3] > 0) {
						return array(
							'width'=>$viewbox[2],
							'height'=>$viewbox[3],
						);
					}
				}
			}

			// Otherwise maybe the width and height are good?
			if (\is_numeric($width) && \is_numeric($height)) {
				$width = (float) $width;
				$height = (float) $height;

				if ($width > 0 && $height > 0) {
					return array(
						'width'=>$width,
						'height'=>$height,
					);
				}
			}
		} catch (\Throwable $e) {
			return false;
		} catch (\Exception $e) {
			return false;
		}

		return false;
	}
Get SVG Dimensions

@param string $svg SVG code or path.
@return array|bool Dimensions. False on failure.