This is a follow up to this question, in witch the jpg compression is altered depending on what WP's built-in image resulting image size returns. While it may work for most of the people, i'm looking for a more discrete and automatic approach. And that is altering the wp_create_thumbnail i think.

The point is this: How to alter the JPG compression of autogenerated thumbnails for an uploaded image? For example, images below 400px width at 60%, and between 401px~100px width at 80%.

  • Not sure this follow up is valid, but let's get into comments here, until we're done. wp_create_thumbnail() has image_save_pre as its first filter, so it should already work.
    – kaiser
    Commented Jul 17, 2012 at 18:21
  • It works if I revert to the old code (hooking directly to jpeg_quality). wp_create_thumbnails is this. Commented Jul 17, 2012 at 20:45
  • 1
    I know what wp_create_thumbnail() is. Currently code is hooking directly... wp_create_thumbnail() is just there to determine, if hooking is needed...
    – kaiser
    Commented Jul 18, 2012 at 0:19

1 Answer 1


i'm looking for a more discrete and automatic approach. And that is altering the wp_create_thumbnail i think.

And that is where you'd be wrong. Here is the entire code for wp_create_thumbnail() from core:

function wp_create_thumbnail( $file, $max_side, $deprecated = '' ) {
    if ( !empty( $deprecated ) )
        _deprecated_argument( __FUNCTION__, '1.2' );
    $thumbpath = image_resize( $file, $max_side, $max_side );
    return apply_filters( 'wp_create_thumbnail', $thumbpath );

This function, on its own, doesn't do much. Instead, if you need to change anything, it would be image_resize() ... but changing the core function is still the wrong way to do this.

Why Not Change Core

Changing a core file is usually frowned upon by mainstream developers. If you change core and don't resubmit your changes to the project, you're left with a forked version of WordPress - the next time an update is released, you'll have to re-edit core files after you update to maintain your new functionality.

In many cases, the changes you want to make to core only apply to a handful of people - typically just you. Unless the changes will benefit a majority of WP users, any core changes outside the scope of the current development cycle will usually be tabled for later or left in Trac with a "wontfix" resolution.

What works for just you or just me doesn't belong in the core project - it belongs in a plugin.

The Right Way

The right way to change things up is to create your own version of image_resize() in a plugin. Then build your own my_create_thumbnail() function that fits the following:

function my_create_thumbnail( $file, $max_side ) {
    return apply_filters( 'wp_create_thumbnail', my_image_resize( $file, $max_side, $max_side ) );

This function has the same signature as wp_create_thumbnail() and fires the same filters, so it can be used as a one-to-one replacement of the original function in all of your other plugin and theme scripts.

  • bounty accepted. I will have to do that to ensure images are compressing nicely. Commented Jul 24, 2012 at 16:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.