Enforce maximum dimensions on image.

From #6470.