Generate a grid image programatically.