Image Masks

Learn how to create an image mask in a separate file and feed that file to our program.

Introducing image masks

These masks were previously compared to images, where each cell is like a pixel that we turn on or off. It might make sense, then, to use actual images for the templates, where pixels of a particular color (say, black) are considered off, and everything else is considered on. This would let us design our templates using an image editor, which should make larger masks a lot easier.

Let’s implement this. We’re going to create a method that will accept an image in PNG format, so the first thing we’ll need to do is make sure the ChunkyPNG library is loaded. To do that, we'll add the following line at the very top of mask.rb:

Get hands-on with 1200+ tech skills courses.