When Uploading JPEGs, Does WordPress Compress the Original Image?

This is all I can get from reading the source code for the wp_handle_upload function in wp-admin/includes/file.php.

  • WordPress keeps the original uploaded file (usually) – see below…
  • WordPress does apply JPEG compression to resized images when the source is a JPEG.
  • The default JPEG compression level is 90.
  • You can adjust the JPEG compression level by adding a jpeg_quality filter:

    add_filter('jpeg_quality', 'ex46632_jpeg_quality');
    function ex46632_jpeg_quality($quality) {
        $quality = 95; // An example of setting the quality to a higher value.
        return $quality;
    }
    
  • You can force an uploaded image to be resized to the Max Width/Max Height specified in Settings > Media > Large size by adding a wp_upload_resize filter:

    add_filter('wp_upload_resize', 'ex46632_upload_resize');
    function ex46632_upload_resize($resize) {
        $resize = true; // Force resizing to the max sizes.
        return $resize;
    }
    
    • If there are any errors in the creation of the resized image the original uploaded file will be kept instead.
    • If resize is successful, original uploaded media is discarded.

Note the code samples here have not been tested and are just for reference.

Update
As commented a change was made to the handling of resizing in the wp_handle_upload function. This change fixes a bug, in order to fix the bug the resize code was actually removed so images are not resized on upload and are kept at their original size.
For your reference explicit code change and bug ticket. It should be noted that this change is still “Awaiting Review to 3.4”, it’s not released yet.

Note also that the ticket has the comment “let Plupload resize images (before uploading)”, so perhaps there is another place to check for the resizing of images now since Plupload is included.