Automatically replace original uploaded image with large image size

As our users regularly upload ~6MB images to use on the website (and aren’t too familiar with how to resize them first), WordPress stores the originals as well as resizing them to several different sizes.

I’d like a function or plugin that takes the uploaded image, resizes it down to something more manageable and then replaces the original.

I’ve seen some functions that delete the original but do not replace it, meaning it is impossible to regenerate the thumbnails at a later date. I need this to be replaced so the user can upload a large image and it is automatically resized down and stored for future resizing if needed.


Add this to the functions.php file in the theme folder. It replaces the original image with the large image set in settings. You might want to setup a new image format and use that as the new original size though.

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']; // ** This only works for new image uploads - fixed for older images below.
  $current_subdir = substr($image_data['file'],0,strrpos($image_data['file'],""));
  $large_image_location = $upload_dir['basedir'] . "".$current_subdir."".$image_data['sizes']['large']['file'];

  // delete the uploaded image

  // rename the large image

  // 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;


Leave a Comment