0
votes

I created a WordPress website on which I have 14 images. I did not resize the image source files, but I installed the Smush plugin to optimize the size of the uploaded images.

However, I need to export my website (public-html directory) and it is totally oversized: 270MB. It is for a school project, and I am asked for a 200MB-max directory only.

When checking the wp-content/uploads directory, I notice that each uploaded image ended up with like 10 duplicates of different sizes. The directory overall size is more that 75MB, which is huge.

Thus I have two questions:

  • Are all those duplicates necessary or can I delete some of them directly from the wp-content/uploads directory?
  • In Smush settings, I can see that it is possible to choose which duplicate sizes we want among all those automatically generated by WordPress. If I change these settings, I suppose I'll have to re-upload all my images, right?
1
Hello again, I deleted all my images from the dashboard. Then I changed Smush settings to only keep two sizes of images and re-uploaded my images. Now, it is even worse... My image folder weighs 90MB... I really don't understand how it works. Does anyone have an idea, please? - Cécile Prézut

1 Answers

0
votes

The "duplicates" you are talking about are, I presume, the different sizes of each image created by your WP setup.

Alternative sizes can be created by:

  • Wordpress by default can create 3 alternative sizes: a thumbnail, a medium image and a large image (as well as keeping the full sized image that was uploaded).
  • Your theme can create other images sizes that it will use.
  • Plugins can also create other sizes that they need.

You can't just delete the additional images or remove that size from being generated and hope for the best. Well-made themes and plugins will only add other image sizes if it uses that size on your website, so removing those images will result in broken images on your website.

Also, even when you delete them, if the code that creates them is also not removed, they will keep getting created when new images are uploaded.

What you could try:

  1. Don't upload very large images The fact that your folder is so big for just 10 images suggests that the photos you are uploading are very large in the first place.
    When Wordpress is creating the alternative sizes, it reduces the pixel size but it doesn't always created a greatly-reduced file size. So if the original images are very large, the alternative sizes are also likely to be larger than needed.

  1. Make sure your optimiser plugin settings are optimal Smush and other optimising plugin might not be reducing the size by much depending on the settings (note that the image itself will also affect this). You might need to change the setting to favour file size over quality. Also make sure it is working on all the alternative image sizes.

  1. Don't keep the original full-sized images. Even if your other sizes are reduced effectively, WP keeps the full-sized image by default after it created the alternative sizes.
    If you know your site doesn't use the full-sized image, you don't need to keep them. Some image optimisation plugins will automatically remove the original, others will give you the option to do this.

  1. Try a different optimiser plugin. There are a number of plugins available, some reduce the size of images automatically on upload (like Smush), others reduce the size on upload only (such as Imsanity. The image itself has a big effect on how easy they are to optimise, so try a different plugin in case it is better for your images.

    In perfomance analysis I've seen, plugins such as the free version of Smush or EWWW don't give great results - the Smush developers even say
    "The free version of the plugin doesn’t perform that well.".

    In comparison, the plugins that use paid subscriptions usualy perform a lot better. Some of these have free versions with limited functionality that could work for you, e.g. reSmush.it (free up to 5MB image size) or ShortPixel Image Optimizer (Free up to 100 images per month)

  1. You can manually delete old sizes if you know they are not being used any longer - for example if a deleted plugin or old theme had added other sizes that were no longer needed. But the fact that they were created again when you added them again shows that they are all being created by active plugins and theme.

  1. You can unset any defined image size if you know it is not being used to prevent them from being created, for example, if you don't use some of the default image sizes created by Wordpress. You can use a plugin to do this, such as Smush or Stop Generating Unnecessary Thumbnails.
    Or you can use the code below in your functions.php - it will also work for other sizes added by themes and plugins, if you pass the name that was used in add_image_size. Note that this only affects new images uploaded - you will need to delete any existing ones.

    function unset_unused_image_sizes( $sizes ){
        unset( $sizes[ 'thumbnail' ]);
        unset( $sizes[ 'medium' ]);
        unset( $sizes[ 'large' ]);
        unset( $sizes[ 'full' ] );
        return $sizes;
    }
    add_filter( 'intermediate_image_sizes_advanced', 'unset_unused_image_sizes' );


  1. Not all the resized images will be used - once the add_image_size is added by a theme or plugin, alternative sizes of all images will be created whether they are used or not. So if you upload photos for use on one specific page only, any sizes created by a gallery plugin for example would not be needed. However you will need to do this on an image-by image basis.

  1. Check for plugin caches. Many gallery plugins will create their own cache of images - depending on the plugin, this might be created in the uploads folder. They do use this cache so you can't remove it permanently, but for the purpose of moving a site you can delete the cache folders before you export your site to reduce the overall size. The plugins should recreate the cache on the new site when you use it (but verify this beforehand to be sure!)

Summary

My guess is that your original images are very large to start with and automatic resizing is not optimising them effectively. My first recommendation is to reduce the size before you upload them - graphics packages are usually much more effective at optimising images than Wordpress and even the plugins. As I say above, the developers of Smush say the "free version of the plugin doesn’t perform that well", so you are better off not relying on it to do the optimisation.