[wp-trac] [WordPress Trac] #62312: wp_image_src_get_dimensions() - Warning for SVG with postmeta height and width empty

WordPress Trac noreply at wordpress.org
Wed Feb 25 23:13:31 UTC 2026


#62312: wp_image_src_get_dimensions() - Warning for SVG with postmeta height and
width empty
--------------------------+------------------------------
 Reporter:  apermo        |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Media         |     Version:  5.5
 Severity:  normal        |  Resolution:
 Keywords:  has-patch     |     Focuses:
--------------------------+------------------------------

Comment (by dmsnell):

 I’ve attached a screenshot of some SVG sizing shenanigans with variations
 of `width=200 height=200` and `viewBox="0 0 200 200"`. the copy missing
 the disc in the render has `width=50 height=50` and no `viewBox`
 attribute.

 > when I set the size in wordpress i expect it to work for any image,
 regardless of raster versus vector.

 my point was in the framing of this change and the claim that SVG’s
 receive no height/width metadata on upload. unlike raster images, which
 typically have an inherent //pixel size//, the SVG’s don’t, although they
 often do have intended sizes and intended size ranges or scaling factors
 as determined by their illustrator/author. technically they are infinite,
 but practically they break down, of course.

 for the patch at hand it seems to check for the presence of the properties
 before reading them and that avoids the warning, but as per the issue of
 SVG I don’t know what good it is to send that metadata along with the
 missing sizes.

 based on the test above, it seems like we could attempt to parse it, very
 conservatively, and use positive matches where available. otherwise, it
 seems like SVG support is really a separate issue here? if we do nothing
 to support them, then nothing gets better, but there will be no warnings
 created…

 {{{#!php
 <?php
 if ( str_ends_with( $image_src, '.svg' ) && is_file( $image_src ) ) {
         // if no complete SVG tag appears at the start then assume it’s
 not there.
         $header    = file_get_contents( $image_src, false, null, 0, 1024
 );
         $processor = new WP_HTML_Tag_Processor( $header );
         if ( $processor->next_token() && 'SVG' === $processor->get_tag() )
 {
                 $width  = $processor->get_attribute( 'width' );
                 $height = $processor->get_attribute( 'height' );

                 if ( is_string( $width ) && is_string( $height ) && 1 ===
 preg_match( '~[ \t\f\r\n]*[+-]?[0-9]+~', $width ) && ... ) {
                         $dimentions = array( (int) $width, (int) $height
 );
                 }
         }
 }
 }}}

 this would, of course be better as a function that gets called here. just
 sharing some ideas; this area is out of my normal operating zone.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/62312#comment:8>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list