[wp-trac] [WordPress Trac] #37549: Add optional parameter to wp_generate_attachment_metadata for image dimensions.

WordPress Trac noreply at wordpress.org
Tue Jan 7 20:05:16 UTC 2020


#37549: Add optional parameter to wp_generate_attachment_metadata for image
dimensions.
-------------------------+------------------------------
 Reporter:  sterlo       |       Owner:  joemcgill
     Type:  enhancement  |      Status:  reviewing
 Priority:  normal       |   Milestone:  Awaiting Review
Component:  Media        |     Version:  4.6
 Severity:  normal       |  Resolution:
 Keywords:  has-patch    |     Focuses:
-------------------------+------------------------------
Changes (by desrosj):

 * milestone:   => Awaiting Review


Old description:

> My plugin [https://wordpress.org/plugins/scalable-vector-graphics-svg/
> Scalable Vector Graphics] received a support request,
> [https://wordpress.org/support/topic/svg-in-image-gallery-is-not-
> working?replies=16#post-8710513 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
> <?php
> function wp_generate_attachment_metadata( $attachment_id, $file ) {
> }}}
> became something like
> {{{#!php
> <?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.

New description:

 My plugin [https://wordpress.org/plugins/scalable-vector-graphics-svg/
 Scalable Vector Graphics] received a support request,
 [https://wordpress.org/support/topic/svg-in-image-gallery-is-not-
 working?replies=16#post-8710513 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
 <?php
 function wp_generate_attachment_metadata( $attachment_id, $file ) {
 }}}
 became something like
 {{{#!php
 <?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.

--

Comment:

 Moving this back to Awaiting Review.

 @sterlo are you still interested in tackling this?

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


More information about the wp-trac mailing list