Saving to file object?

42 views
Skip to first unread message

Martin7

unread,
Feb 22, 2016, 1:30:38 PM2/22/16
to blockdiag-discuss
Hello,

Is it possible to save a diagram in a Python file object to be used as dynamic image on a web app?


Thank you,

shirou

unread,
Feb 22, 2016, 8:16:03 PM2/22/16
to blockdiag-discuss
Hi,


blockdiag.drawer.DiagramDraw.save() returnes image object.
For example, this is a part of blockdiag command.

https://bitbucket.org/blockdiag/blockdiag/src/07f96892bfda92b84f624afab987015f26ff7ff0/src/blockdiag/command.py?at=default&fileviewer=file-view-default

And as you can see, I changed to print the DiagramDraw returned
object and pass None as a filename.
If "svg" is passed to DiagramDraw, the output is XML string.
If "png" is passed, the output is png formatted binary object.


#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import

import sys
import blockdiag
import blockdiag.builder
import blockdiag.drawer
import blockdiag.parser
from blockdiag.utils.bootstrap import Application, Options

class BlockdiagApp(Application):
module = blockdiag

def build_diagram(self, tree):
DiagramBuilder = self.module.builder.SeparateDiagramBuilder
DiagramDraw = self.module.drawer.DiagramDraw

for i, group in enumerate(DiagramBuilder.build(tree)):
draw = DiagramDraw("svg", group, None, # <---- I CHANGED to None!
fontmap=self.fontmap,
antialias=self.options.antialias,
nodoctype=self.options.nodoctype,
transparency=self.options.transparency)
draw.draw()
print(draw.save()) # <---- I ALSO CHANGED HERE!

return 0

if __name__ == '__main__':
BlockdiagApp().run(sys.argv[1:])


----
WAKAYAMA Shirou


2016年2月23日 3:30 Martin7 <marti...@gmail.com>:
> --
> このメールは Google グループのグループ「blockdiag-discuss」に登録しているユーザーに送られています。
> このグループから退会し、グループからのメールの配信を停止するには
> blockdiag-disc...@googlegroups.com にメールを送信してください。
> その他のオプションについては https://groups.google.com/d/optout にアクセスしてください。

Martin7

unread,
Feb 23, 2016, 11:45:40 AM2/23/16
to blockdiag-discuss
Hi, thank you.
I will try, kind regards.
Reply all
Reply to author
Forward
0 new messages