3
After the upload of an image in wordpress I would like to make a check if the registered image is larger than the stated limit size, if it is larger I want to delete the original image in the folder upload and keeps only images cropped with thumbnails (media).
I’m using this function on functions.php
add_filter( 'wp_generate_attachment_metadata', 'delete_fullsize_image' );
function delete_fullsize_image( $metadata )
{
$upload_dir = wp_upload_dir();
$full_image_path = trailingslashit( $upload_dir['basedir'] ) . $metadata['file'];
$deleted = unlink( $full_image_path );
return $metadata;
}
Example:
I specified that the maximum image size will be 300x300, when sending a 350x350 image it cuts the image to 300x300 size and excludes the original 350x350 image.
How is it possible to do that?