Opened 9 years ago
Last modified 5 years ago
#37549 reviewing enhancement
Add optional parameter to wp_generate_attachment_metadata for image dimensions.
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 4.6 |
Component: | Media | Keywords: | has-patch |
Focuses: | Cc: |
Description (last modified by )
My plugin Scalable Vector Graphics received a support request, SVG in image gallery is not working -- which caused me to do some digging in core.
I realized the reason the Theme wasn't doing what it intended to do is because it is reyling on
wp_get_attachment_metadata()
-- which lead me to realize that SVG files -- although being uploaded and working for the most part, are missing the meta information normally generated for images such as JPG files.
The function that does that is wp_generate_attachment_metadata
.
The reason it is not doing that is because file_is_displayable_image
is returning false, which I can override if I want with the filter -- BUT -- the function also depends on getimagesize
-- which I cannot navigate around and does not work with SVG files.
It would be cool if
<?php function wp_generate_attachment_metadata( $attachment_id, $file ) {
became something like
<?php function wp_generate_attachment_metadata( $attachment_id, $file, $dimensions = false ) {
SVG files are displayable -- and file_is_displayable_image
is a well meaning function but it's not really determining if a file is displayable. It's determining if an image will work with getimagesize
.
The Ask: Let's allow developers to pass dimensions to wp_generate_attachment_metadata
so that we allow for future file types that are web friendly to exist within WordPress, with the support of plugins, and that useful information about those uploaded files is generated in a controllable and consistent manner.
Right now, the recourse I have as a plugin developer is to copy wp_generate_attachment_metadata
and generate my meta data within the plugin. Which I isn't a problem, but I feel this request nudges image.php
into a direction it's going to need to go sooner or later anyway.
Attachments (2)
Change History (10)
This ticket was mentioned in Slack in #core-images by sterlo. View the logs.
9 years ago
#3
@
9 years ago
- Keywords has-patch added
Here is an example of how this could be leveraged by Plugin/Theme developers if the patch were to be implemented:
https://gist.github.com/grok/e257ea85a492ab267fd1f0b28fdafe03
#4
@
9 years ago
- Owner set to joemcgill
- Status changed from new to reviewing
Hi @sterlo,
Thanks for the detailed description and initial patch. I think you might be able to accomplish what you need to with a filter on the output of wp_generate_attachment_metadata()
. In reality, you don't want to jump into the first branch of that if
statement, because the only metadata you need is the height, width, and file—not the additional intermediate sizes.
Could you get the attachment_id
from the filter, see if the attachment is an SVG, and then generate those three pieces of data (most of which you demonstrated in your gist)? This would also avoid the getimagesize()
issues you run into in file_is_displayable_image()
as well.
#6
in reply to:
↑ 5
@
8 years ago
Replying to sterlo:
@joemcgill I will take a stab at it and report back.
Hi @sterlo any update on whether the approach mentioned above would get you what you need here?
Patch that introduces optional parameter.