Open the image in its best version
I made this script to work only with IMAGES, but it works with any format. If you want it to work for any file type, remove the IF operation or add the desired file extensions in the allowedExtensions array.
const allowedExtensions = ['jpg', 'jpeg', 'png', 'mp4', 'webm', 'gif']