Adding logic to improve image quality when resizing