Enforce maximum dimensions on image.

From #6470.
Nice