def _build_diagram(module, builder, drawer, tree, type, code, fontmap=None,
    antialias=True, nodoctype=False, transparency=False, size=None):
    """
    Inspired from :epkg:`blockdiag` source file (*_bootstrap.py*).
    """
    ScreenNodeBuilder = builder.ScreenNodeBuilder
    diagram = ScreenNodeBuilder.build(tree, None)
    DiagramDraw = drawer.DiagramDraw
    drawer = DiagramDraw(type, diagram, fontmap=fontmap, code=code,
        antialias=antialias, nodoctype=nodoctype, transparency=transparency)
    drawer.draw()
    if size:
        return drawer.save(size=size)
    else:
        return drawer.save()
