When Uploading JPEGs, Does WordPress Compress the Original Image?

I’m trying to determine what my image processing workflow should look like. I know WordPress automatically resizes and compresses images to various different sizes on upload. I’m curious if it does any compression on the original image.

Since it’s doing compression (as it should) on the smaller images, I wouldn’t want to upload an already compressed JPEG to have it re-compressed on the smaller sizes. But, if it doesn’t compress the original, I’ll have much larger image file than necessary when someone goes to view the original.

I’m thinking the ideal workflow would be to upload a quality 100 JPEG to WordPress, have it resize and compress all of the smaller images using the full quality image, and then compress the original as well. Does anyone know if this is possible (or if this is what is being done already)?

Solutions Collecting From Web of "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.