Make WordPress Core

Opened 2 years ago

Last modified 6 weeks ago

#57239 new defect (bug)

Notice undefined array keys width and height when using full svg image

Reported by: joeyjanson's profile joeyjanson Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 6.1.1
Component: Media Keywords: has-patch
Focuses: Cc:

Description (last modified by sabernhardt)

If you add media like an svg and use it with the "full size" option the width and height are not fetched. Currently the _wp_get_image_size_from_meta() function (wp-includes/media.php line 1185) expects those array keys.

Change History (10)

This ticket was mentioned in PR #3711 on WordPress/wordpress-develop by JoeyJanson.


2 years ago
#1

If you add media like an svg and use it with the "full size" option the width and height are not fetched. Currently the function expects those array keys. This PR checks both of the keys and if one of the keys are empty return false.

Trac ticket: 57239

#2 follow-up: @florianreintgen
15 months ago

Had the same problem today, looking for a solution for this

#3 in reply to: ↑ 2 @joeyjanson
15 months ago

Replying to florianreintgen:

Had the same problem today, looking for a solution for this

Well I fixed this in december 2022 and also delivered a pull request but it is not merged, used or responded so no clue if it will ever be fixed.. PR link to see the change: https://github.com/WordPress/wordpress-develop/pull/3711

#4 @hellofromTonya
2 months ago

#61997 was marked as a duplicate.

#5 @internationils
2 months ago

FYI...

This ticket (#61997) was mentioned in PR #7307 on WordPress/wordpress-develop by navinrangar.

Keywords has-patch added

Wrote a check to see if the 'key' we are trying to access does exist in the object or not.

Trac ticket:
https://core.trac.wordpress.org/ticket/61997#no0

Also, in Bug #61997 the Version was changed to 4.4.0 since the bug apparently existed since then. If this is indeed a dupe, please also change the version here

#7 @internationils
2 months ago

  • Keywords needs-design-feedback added

Currently on different lines:

2024-09-16_01:07:11_PHP Warning:  Undefined array key "height" in /srv/data/web/vhosts/MYSITE.COM/htdocs/wp-includes/media.php on line 1242
2024-09-16_01:07:11_PHP Warning:  Undefined array key "width" in /srv/data/web/vhosts/MYSITE.COM/htdocs/wp-includes/media.php on line 1241

They are coming from the code below... any chance of catching the error and hinting at where it is coming from (what file, possibly an SVG or something with dimensions not specified?) As is, its pretty hard to figure out whats causing it and if its a real problem or an annoyance.

https://github.com/WordPress/wordpress-develop/blob/8e89a9856e3d8369225df0c63cb6911ec884ab4f/src/wp-includes/media.php#L1241

#8 @internationils
8 weeks ago

Hello, what is missing from this case to move forward? I am getting thousands of these messages a day on a site and not seeing the "real" errors. Is there a way to indicate which file it is, or consider it noncritical, or anything to stop it from spamming the logs?

#9 @sabernhardt
6 weeks ago

  • Description modified (diff)
  • Keywords needs-design-feedback removed

#10 @sabernhardt
6 weeks ago

The _wp_get_image_size_from_meta() docblock says it returns "false if the size isn't present in the meta data," and SVG images do not have width or height for full-size in the metadata. If this function is where the change should be made, returning false when the dimensions are not set could be more appropriate than an array of zeroes.

if ( ! isset( $image_meta['width'] ) || ! isset( $image_meta['height'] ) ) {
	return false;
}

However, #55247 seems to report an error when the function returns false (the function using it might have needed to account for a Boolean response).

I found two uses of the function in core:


Also related to missing SVG metadata:

  • #57813 mentions wp_get_missing_image_subsizes() and wp_image_src_get_dimensions().
  • The wp_get_attachment_metadata() function can show notices on the image attachment page when the theme template expects width and height in the array (if the themes need editing, that includes Twenty Ten to Twenty Sixteen, plus Twenty Nineteen and Twenty Twenty-One).
Note: See TracTickets for help on using tickets.