The hard part was knowing which part of the image is the shape. If the image has transparency, I use the alpha channel. If not, I estimate the background color from the median of the border pixels and split by color distance with Otsu. Brightness alone wasn't enough: in the Python logo, the yellow is almost as light as the white background.
Then I fill the holes, but only what touches the border counts as background. That way a cat's white belly on a white background is still cat. The shape is reduced to a character grid (correcting for terminal letters being about twice as tall as they are wide), and the text is written by grapheme so accents and emoji don't get split.
Before writing the poem, you can ask the library how many letters fit and at what width the whole text fits. It helped me fit the text to the shape instead of the other way around.