Forums

Nasty JPEG Compression (NOT related to header) (3 posts)

  1. hmccorkle
    Member
    Posted 2 years ago #

    whenever i upload any image and have the thumbnail displayed, the jpeg compression appears to be around 40 or something like that.

    it looks nasty.

    what's the file i can edit in order to adjust the compression?

    i'll post samples on my site: http://grizzlyelephant.com

  2. Otto42
    Moderator
    Posted 2 years ago #

    The default is actually 75. The quality difference you see is more likely due to the image resizing algorithm that the PHP/GD library has (which is only bilinear, I think).

    If you look in admin-functions.php, and look for function wp_create_thumbnail, this is where it's making the thumbnail file.

    Scroll down and you'll see this code:

    // move the thumbnail to its final destination
    if ( $type[2] == 1 ) {
    	if (!imagegif( $thumbnail, $thumbpath ) ) {
    		$error = __( "Thumbnail path invalid" );
    	}
    }
    elseif ( $type[2] == 2 ) {
    	if (!imagejpeg( $thumbnail, $thumbpath ) ) {
    		$error = __( "Thumbnail path invalid" );
    	}
    }
    elseif ( $type[2] == 3 ) {
    	if (!imagepng( $thumbnail, $thumbpath ) ) {
    		$error = __( "Thumbnail path invalid" );
    	}
    }

    This is where it saves the thumbnail file. Note this line:
    if (!imagejpeg( $thumbnail, $thumbpath ) ) {

    That saves the image to a jpg file if needed. No quality is specified, so it's using the default of 75.

    To change it, edit that line like so:
    if (!imagejpeg( $thumbnail, $thumbpath, 80 ) ) {

    Where 80 is whatever compression you want (0-100).

  3. hmccorkle
    Member
    Posted 2 years ago #

    Thank you. So. Much.

Topic Closed

This topic has been closed to new replies.

About this Topic