Reimplements fixes needed to resize image on upload (not sure how they were reverted)