Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function bodhi_svgs_get_dimensions( $svg = '') {
- // Default Response
- $response = (object)[
- 'width' => '0',
- 'height'=> '0'
- ];
- // Where should this file be
- $template_uri = wp_upload_dir();
- $svg_basename = basename($svg);
- $svg_file = $template_uri . '/' . $svg_basename;
- // Is this file where we think it should be?
- if(file_exists($svg_file) && is_readable($svg_file)) {
- // It's supposed to be an SVG; can we load it like one?
- $svg = @simplexml_load_file( $svg );
- // A really deep SVG may break and return false, even if valid
- // But assuming it's not too deep, and can be read, then let's go
- if (false !== $svg) {
- $attributes = $svg->attributes();
- $response->width = (string)$attributes->width;
- $response->height = (string)$attributes->height;
- }
- }
- return $response;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement