tweaked image resizing implementation