Check image file size before the format

Checking the file format may take a long time if the uploaded file is
very big so it makes sense to check the file size first to prevent the
server being held up unneccessarily.