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

		try {

			$svgs = $dom->getElementsByTagName('svg');
			if (!$svgs->length) {
				return false;
			}

			$svg = $svgs->item(0);

			$width = $svg->hasAttribute('width') ? $svg->getAttribute('width') : null;
			$height = $svg->hasAttribute('height') ? $svg->getAttribute('height') : null;
			$viewbox = $svg->hasAttribute('viewBox') ? $svg->getAttribute('viewBox') : null;

			// 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) {
			error_log($e->getMessage());
			return false;
		} catch (\Exception $e) {
			return false;
		}

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

		try {

			$svgs = $dom->getElementsByTagName('svg');
			if (!$svgs->length) {
				return false;
			}

			$svg = $svgs->item(0);

			$width = $svg->hasAttribute('width') ? $svg->getAttribute('width') : null;
			$height = $svg->hasAttribute('height') ? $svg->getAttribute('height') : null;
			$viewbox = $svg->hasAttribute('viewBox') ? $svg->getAttribute('viewBox') : null;

			// 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) {
			error_log($e->getMessage());
			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.