No attachment meta data
-
As a dev I found myself needing the height and width of an attachment. This plugin doesn’t fill in fields that
wp_get_attachment_metadata()
should return. A function to get the height and width of an svg file might look something like the code below. Please consider adding this feature to your already amazing plugin.function find_svg_dimensions( $svgUrl ) { $svgString = file_get_contents($svgUrl); $svgElement = simplexml_load_string($svgString); // do a return check here to see if height and width even exist // if (check) return false; $height = intval($svgElement['height']); $width = intval($svgElement['width']); if ( ! isset($height) || ! isset($width) ) { $viewBox = explode(' ', $svgElement['viewBox']); // check if $viewBox is set if ( ! isset($viewBox) ) return false; // https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/viewBox $minX = intval($viewBox[0]); $minY = intval($viewBox[1]); $width = intval($viewBox[2]); $height = intval($viewBox[3]); $width = $width - $minX; $height = $height - $minY; } return array( "height" => $height, "width" => $width ); }
I didn’t fully test this code, so take it with a grain of salt.
THANKS!
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘No attachment meta data’ is closed to new replies.