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

WordPress Trac noreply at wordpress.org
Tue Aug 2 22:00:42 UTC 2016


#37549: Add optional parameter to wp_generate_attachment_metadata for image
dimensions.
-------------------------+-----------------------------
 Reporter:  sterlo       |      Owner:
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  Upload       |    Version:  trunk
 Severity:  normal       |   Keywords:
  Focuses:               |
-------------------------+-----------------------------
 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.

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


More information about the wp-trac mailing list