Created
May 3, 2021 09:56
-
-
Save rustam-swe/250e6c256b8b0f26d065ab7f01131511 to your computer and use it in GitHub Desktop.
Returns dimensions (width and height) of a given svg (by url)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Returns dimensions (width and height) of a given svg (by url) | |
* | |
* @param string $image_url | |
* @source https://stackoverflow.com/a/6532357/9214537 | |
* | |
* @return string | |
*/ | |
function get_svg_dimensions( string $image_url ): string { | |
$parsed_xml = simplexml_load_string( file_get_contents( $image_url ) ); | |
$svg_attributes = $parsed_xml->attributes(); | |
$width = (string) $svg_attributes->width; | |
$height = (string) $svg_attributes->height; | |
return "width=\"{$width}\" height=\"{$height}\""; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment