easy_svg_read_svg_dimensions()
Reads the width and height attributes of an SVG on disk, failing safely.
Function · Easy SVG · Status: Internal · Defined in easy-svg.php
Internal: not part of the promised public surface. It may change without notice.
Usage
easy_svg_read_svg_dimensions( string $path ): array
Example
$dim = easy_svg_read_svg_dimensions( get_attached_file( $attachment_id ) );
$width = $dim['width'] ?? 0;
Description
Returns array( 'width' => int, 'height' => int ) from the root attributes, or an empty array when the path is not a file, the file is over easy_svg_max_bytes(), SimpleXML is missing or parsing fails. Values are cast with (int), so 100% or 2em read as 100 and 2, and a missing attribute as 0. It never reads viewBox.
Parameters
body
$pathstring
Absolute file path.
Return value
returnarray
width and height, or an empty array.
Related
Was this page helpful?