More robust image resizing (Issue 2207)