That's tricky, if the shapes can be anything. I imagine using the canvas plugin to take a snapshot, then count contiguous pixels with a flood fill would be a straightforward way to go about it.
Edit: or rather than a flood fill, sizing the canvas to fit the shape and scanning line by line would be even more straightforward.