[wp-trac] [WordPress Trac] #26256: SVG images get width and height attributes with values 1

WordPress Trac noreply at wordpress.org
Thu Nov 28 07:40:33 UTC 2013


#26256: SVG images get width and height attributes with values 1
--------------------------+------------------------------
 Reporter:  lippe         |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Media         |     Version:
 Severity:  normal        |  Resolution:
 Keywords:                |
--------------------------+------------------------------

Comment (by lippe):

 A possible workaround for this is to filter 'image_downsize' and for SVG
 files return null values for width and height:


 {{{
 /**
  * Removes the width and height attributes of <img> tags for SVG
  *
  * Without this filter, the width and height are set to "1" since
  * WordPress core can't seem to figure out an SVG file's dimensions.
  *
  * For SVG:s, returns an array with file url, width and height set
  * to null, and false for 'is_intermediate'.
  *
  * @wp-hook image_downsize
  * @param mixed $out Value to be filtered
  * @param int $id Attachment ID for image.
  * @return bool|array False if not in admin or not SVG. Array otherwise.
  */
 function wg_fix_svg_size_attributes( $out, $id )
 {
         $image_url  = wp_get_attachment_url( $id );
         $file_ext   = pathinfo( $image_url, PATHINFO_EXTENSION );

         if ( ! is_admin() || 'svg' !== $file_ext )
         {
                 return false;
         }

         return array( $image_url, null, null, false );
 }
 add_filter( 'image_downsize', 'wg_fix_svg_size_attributes', 10, 3 );
 }}}

--
Ticket URL: <http://core.trac.wordpress.org/ticket/26256#comment:3>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list