예제 #1
0
파일: views.py 프로젝트: sumikawa/diag2img
def show(request, diag):
    tree = diagparser.parse(diagparser.tokenize(bz2.decompress(
                base64.b64decode(diag.replace('-', '/'))).decode('utf-8')))
    diagram = builder.ScreenNodeBuilder.build(tree)
    response = HttpResponse(mimetype='image/png')
    draw = DiagramDraw.DiagramDraw('PNG', diagram, response, antialias=False, font=settings.FONT)
    draw.draw()
    draw.save()
    return response
def nwdiag_generate_image(source):
    import nwdiag
    from nwdiag import diagparser, builder, DiagramDraw

    try:
        tree = diagparser.parse(source)
        diagram = builder.ScreenNodeBuilder.build(tree)
        draw = DiagramDraw.DiagramDraw('SVG', diagram)
        draw.draw()

        svg = draw.save('').decode('utf-8')
        etype = None
        error = None
    except Exception, e:
        svg = ''
        etype = e.__class__.__name__
        error = str(e)