WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 9 months ago

#23401 closed enhancement (fixed)

Pass $metadata to intermediate_image_sizes_advanced filter

Reported by: amereservant Owned by: wonderboymusic
Milestone: 4.4 Priority: normal
Severity: normal Version: 3.5
Component: Post Thumbnails Keywords: has-patch
Focuses: Cc:

Description

I'm requesting that the following patch be added, which simply passes the $metadata for the image to be used for the new post thumbnail sizes to any filters hooking the intermediate_image_sizes_advanced filter in the wp_generate_attachment_metadata function.

The purpose of this is for altering the size of a custom thumbnail size based on the given image's dimensions. For example, I have a need for an post image size that's a minimum dimension size of 200px. The default behavior will allow me to specify a maximum dimension size, but not a minimum.
So by hooking this filter, I can alter the $sizes array and correct the size of my custom post thumbnail size based on the current image's dimensions.

Attachments (2)

image.php.patch (539 bytes) - added by amereservant 3 years ago.
Proposed filter variable
23401.diff (847 bytes) - added by wonderboymusic 9 months ago.

Download all attachments as: .zip

Change History (10)

@amereservant
3 years ago

Proposed filter variable

#1 follow-up: @markoheijnen
3 years ago

Interesting idea. You can't use the filter 'image_resize_dimensions' because of not knowing the image size and a custom image editor for this seems redundant.

#2 in reply to: ↑ 1 @amereservant
3 years ago

Replying to markoheijnen:

Interesting idea. You can't use the filter 'image_resize_dimensions' because of not knowing the image size and a custom image editor for this seems redundant.

Yeap. I discovered it after hacking Viper007Bond's Regenerate Thumbnail plugin and trying to make a basic size check. I realized that a simple post thumbnail size hook wasn't possible, yet it could be by passing the $metadata as a var parameter to the filter.

It doesn't hurt the performance any to add this and it'd be useful to us geeks that dive way too far into WP code, attempting to write proper plugins.

#3 @SergeyBiryukov
3 years ago

  • Milestone changed from Awaiting Review to 3.6
  • Version changed from trunk to 3.5

#4 @DrewAPicture
3 years ago

image.php.patch seems pretty straightforward, testing against the passed $metadata works for me.

#5 @ocean90
3 years ago

  • Milestone changed from 3.6 to Future Release

#6 @chriscct7
9 months ago

  • Keywords needs-refresh needs-docs added
  • Milestone changed from Future Release to 4.4
  • Owner set to chriscct7
  • Status changed from new to assigned

#7 @wonderboymusic
9 months ago

  • Keywords needs-refresh needs-docs removed
  • Owner changed from chriscct7 to wonderboymusic

#8 @wonderboymusic
9 months ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 34007:

In wp_generate_attachment_metadata(), also pass $metadata to the intermediate_image_sizes_advanced filter.

Props amereservant, wonderboymusic.
Fixes #23401.

Note: See TracTickets for help on using tickets.