Support » Plugin: SVG Support » No attachment meta data

  • Resolved James Bradford


    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;
    		$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.


Viewing 1 replies (of 1 total)
  • Plugin Author Benbodhi


    Thanks for your support and for providing this code!
    I also have another piece I’ve been wanting to put in for a while. There’s just been so much happening, I really haven’t had time to do any of the things I want to lately.

    I’m hoping to be settled as of a couple of weeks form now, so will hopefully be able to spend some time on this plugin and get the list of things I want to do ticked off.

    I really appreciate your time to offer this up.


Viewing 1 replies (of 1 total)
  • The topic ‘No attachment meta data’ is closed to new replies.