Let's use pillow to build an image as shown in this stack. With this markdown code:
```genhtml format=png
from PIL import Image
image = Image.new('RGB', (60, 30), color='red')
import io
import base64
with io.BytesIO() as output:
image.save(output, format='png')
print(base64.b64encode(output.getvalue()).decode())
```
We get:
from PIL import Image
image = Image.new('RGB', (60, 30), color='red')
import io
import base64
with io.BytesIO() as output:
image.save(output, format='png')
print(base64.b64encode(output.getvalue()).decode())
Note that it can also be done in only two lines with the png-image
footer:
```genhtml format=png footer=png-image
from PIL import Image
image = Image.new('RGB', (60, 30), color='green')
```
Giving us:
from PIL import Image
image = Image.new('RGB', (60, 30), color='green')