optimally resize images before saving