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 | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 6.1.1 |
Component: | Media | Keywords: | has-patch |
Focuses: | Cc: |
Description (last modified by )
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
#3
in reply to:
↑ 2
@
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
#5
@
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
@
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.
#8
@
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?
#10
@
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:
- wp_calculate_image_sizes(), which checks for Boolean but not whether the array has missing parts
- classic Image widget, which accounts for
empty
Also related to missing SVG metadata:
- #57813 mentions
wp_get_missing_image_subsizes()
andwp_image_src_get_dimensions()
. - The
wp_get_attachment_metadata()
function can show notices on the image attachment page when the theme template expectswidth
andheight
in the array (if the themes need editing, that includes Twenty Ten to Twenty Sixteen, plus Twenty Nineteen and Twenty Twenty-One).
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