Remove the original image from the server after Wordpress generates the thumbnails

3

I need to remove the original image that gives rise to Wordpress thumbnails after the thumbnails are generated. I have 3 sizes of thumbs that I use, however to prevent the server from getting unnecessary files I need to remove the original, which usually comes with more than 4000px in size and over 2.5MB in size. I searched for some content related to this question but I did not find anything. Removing the original after the thumbnails have been generated is it possible? And if so how can I find the answer?

    
asked by anonymous 01.12.2014 / 14:44

2 answers

2

You can do this by using the following code:
(Source: How to automatically use resized images instead of originals )

add_filter( 'wp_generate_attachment_metadata', 'replace_uploaded_image' );

function replace_uploaded_image($image_data) 
{
    // abortar se não houver versão "large" da imagem
    if ( !isset($image_data['sizes']['large']) ) 
        return $image_data;

    // paths do upload e da imagem grande
    $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'];

    // deletar original
    unlink($uploaded_image_location);

    // renomear a imagem "large"
    rename($large_image_location, $uploaded_image_location);

    // atualizar o metadata da imagem e retornar
    $image_data['width']  = $image_data['sizes']['large']['width'];
    $image_data['height'] = $image_data['sizes']['large']['height'];
    unset($image_data['sizes']['large']);

    return $image_data;
}

You can also change the large version to a custom version, as seen in Auto-modifying original [full size] images :

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

And then, just change all occurrences of $image_data['sizes']['large'] by $image_data['sizes']['new-large'] .

    
26.11.2015 / 09:49
0

Look ... I believe only manually. You can find them either in the FTP folder: wp-content / uploads / or in the Media Library.

However, I see no need to remove the images. The vast majority of hosts usually have more than 5GB of space, which is quite difficult to "fill". :)

    
07.12.2014 / 03:34