# Lower Quality for Small Thumbnails, Higher for Large Images

> Saves small thumbnails with stronger compression and large images with higher quality, so grids load fast while hero images stay crisp, instead of one quality for everything.

- Type: PHP
- Runs: Run everywhere
- Category: [Media](https://wpide.com/library/category/media/)
- Tags: image-quality, thumbnails, performance
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/media-quality-by-image-size/

## Code

```php
// Width threshold and the two quality levels.
$wpide_small_size_px = 400;
$wpide_small_quality = 70;
$wpide_large_quality = 88;

add_filter( 'wp_editor_set_quality', function ( $quality, $mime_type, $size = array() ) use ( $wpide_small_size_px, $wpide_small_quality, $wpide_large_quality ) {
    if ( ! in_array( $mime_type, array( 'image/jpeg', 'image/webp' ), true ) || empty( $size['width'] ) ) {
        return $quality;
    }

    return (int) $size['width'] <= $wpide_small_size_px ? $wpide_small_quality : $wpide_large_quality;
}, 10, 3 );
```

## Notes

Needs WordPress 6.8+, which tells the quality filter which size is being made; applies to JPEG and WebP images created from now on.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Lower Quality for Small Thumbnails, Higher for Large Images" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
