WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to make WordPress process Full size images, which by default it leaves unmodified?

share|improve this question
Unmodified as in not resizing the picture? Your question is a bit ambiguous. – mystline Apr 13 '12 at 8:45
Problem: people upload huge images and WordPress leaves them as they are. I need to find a way to optimize Full size images, but there is no such option in the admin area. – Dan Apr 13 '12 at 10:07
Under Media, you have 3 sizes options by default. – Wyck Apr 13 '12 at 15:09
yup, but I need to compress the "Full size" image as the title and my question obviously state. – Dan Apr 14 '12 at 4:26
up vote 3 down vote accepted

Yes, there is.

Found here:

It will replace the original picture with the large size, defined in Media Settings (/wp-admin/options-media.php).

Here's the code:


function replace_uploaded_image($image_data) 
    // if there is no large image : return
    if ( !isset($image_data['sizes']['large']) ) 
        return $image_data;

    // paths to the uploaded image and the large image
    $upload_dir              = wp_upload_dir();
    $uploaded_image_location = $upload_dir['basedir'] . '/' . $image_data['file'];
    $large_image_location    = $upload_dir['path'] . '/' . $image_data['sizes']['large']['file'];

    // delete the uploaded image

    // rename the large image
    rename($large_image_location, $uploaded_image_location);

    // update image metadata and return them
    $image_data['width']  = $image_data['sizes']['large']['width'];
    $image_data['height'] = $image_data['sizes']['large']['height'];

    return $image_data;

It is possible to use it with a custom size:

add_image_size( 'new-large', 1600, 1200 ); 

Changing all the occurrences of $image_data['sizes']['large'] in the original code with $image_data['sizes']['new-large']

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.