WordPress.org

Make WordPress Core

Opened 4 years ago

Last modified 3 years ago

#14106 assigned enhancement

Post-processing of post thumbnails

Reported by: nkuttler Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 3.0
Component: Post Thumbnails Keywords: dev-feedback
Focuses: Cc:

Description

I'm not sure if I'm missing something, but it looks like there is no hook to post-process post thumbnails. I want to add rounded corners to all thumbnails for a theme.

It looks to me like an action at the end of image_make_intermediate_size() in media.php with $file as parameter might do the trick. I'm not sure if that's the right place or when that function is called precisely though. So it might be necessary to add additional parameters to the function call to identify where the call came from.

Attachments (2)

image_resize_post_process.diff (3.8 KB) - added by nkuttler 3 years ago.
First draft, make post-processing and renaming of thumbnails possible depending on named image_size
demo-plugin.php (351 bytes) - added by nkuttler 3 years ago.
Small demo how the new filters can be used to post-process post thumbnails from a plugin/theme

Download all attachments as: .zip

Change History (14)

comment:1 scribu4 years ago

You know you can make rounded corners on images using CSS, right?

comment:2 nacin4 years ago

  • Keywords close added; post process removed

Yeah, I'd just round them through CSS.

You could also utilize the image_make_intermediate_size filter as a regular action hook if necessary, just make sure you return what you receive.

Works for me?

comment:3 nkuttler4 years ago

  • Cc office@… added

Does image_make_intermediate_size only run once per post thumbnail? I wasn't sure if that's the case. It would also be nice if the filter had some info which thumbnail size is being created, although I guess I could identify the image in the filter. But even then it would not be trivial to have post thumbnails of the same size with different effects.

As for round corners that's just an example. Add graphical borders, apply contrast filters, make black & white, sepia filter, etc.

comment:4 nacin3 years ago

  • Keywords reporter-feedback added; close removed

If the filter doesn't quite work for you, we can add context etc.

comment:5 nkuttler3 years ago

I just had a look at the code again and it looks to me like implementing something like add_image_size( 'frontpage-black-and-white' ) is impossible if a differently named image_size is defined with the same dimensions.

Adding context to the filter would work, but image_make_intermediate_size() currently only receives $file, $width, $height and $crop, not the image_size by name. This could be modified easily I think.

Or maybe additional apply_filters( 'image_make_intermediate_size_$image_size_name', $filter )?

I could work on a patch if this is sounds acceptable.

comment:6 nkuttler3 years ago

I meant

$resized_file = apply_filters('image_make_intermediate_size_$image_size_name', $resized_file);

nkuttler3 years ago

First draft, make post-processing and renaming of thumbnails possible depending on named image_size

nkuttler3 years ago

Small demo how the new filters can be used to post-process post thumbnails from a plugin/theme

comment:7 nkuttler3 years ago

  • Keywords dev-feedback added; reporter-feedback removed

Messing with the resized image name wasn't really useful, it's better to hook directly into image_resize().

comment:8 nkuttler3 years ago

  • Owner set to nkuttler
  • Status changed from new to assigned

comment:9 nkuttler3 years ago

By the way, my patch would also make it possible to move the default downgrading of thumbnail image quality to a filter that users can remove. Not sure why the quality is reduced to 90.

comment:11 nacin3 years ago

  • Milestone changed from Awaiting Review to Future Release

Looks like a worthy improvement. Let's revisit in 3.2.

comment:12 nkuttler3 years ago

  • Owner nkuttler deleted
Note: See TracTickets for help on using tickets.