Set jpeg_quality for certain post-types

Without using timthumb, does anyone know of a way to set jpeg_quality for certain post-types or posts?

Related posts

Leave a Reply

2 comments

  1. You can hook into the jpeg_quality filter and do a check for the post type you want to apply the filter to.

    add_filter( 'jpeg_quality', 'my_jpeq_quality' );
    function my_jpeg_quality( $quality ) { 
    if ((isset($_GET['post_type']) && $_GET['post_type'] == 'your_post_type') || (isset($post_type) && $post_type == 'your_post_type')) :
    
    return 100;  //Set quality here
    
    endif;
    
     }
    
  2. add_filter( 'jpeg_quality', 'wpse_39179_jpeg_quality_for_post_type' );
    
    function wpse_39179_jpeg_quality_for_post_type( $quality ) {
    
        if ( ( isset($_GET['post_type'] ) && $_GET['post_type'] == 'post_type_slug' ) || ( isset( $post_type ) && $post_type == 'post_type_slug' ) ){
    
            // For this post type, we want 100% quality
            return '100';
    
        }else{
    
            // Otherwise, revert back to what was passed into this filter to allow us to modify it elsewhere
            return $quality;
    
        }
    
    }/* wpse_39179_jpeg_quality_for_post_type() */