Factored out image resize calculation