glejeune / Ruby-Graphviz

[MIRROR] Ruby interface to the GraphViz graphing tool
https://gitlab.com/glejeune/ruby-graphviz
Other
608 stars 116 forks source link

Is there a way to get ruby-graphviz to output to a base64 encoded image? #143

Closed epasquali closed 4 years ago

epasquali commented 4 years ago

I'm using ruby-graphviz inside a Ruby on Rails project (a web application). I'm generating my graph from a model and so far so good, but from what I understand the output method only enables me to generate the graph pictures as files.

This presents a problem for me because this means I first have to save the file, then serve it up again in the same action. This is inefficient and slow.

Ideally, I would like graphviz to output the resulting graph in some sort of string or base64 encoded format so that it wouldn't need to be saved in a file, just stored as a variable, and then I can call up that variable to display the graph in my view.

Is there a way to do that at the moment? I can't glean from the documentation if one can at the moment.

epasquali commented 4 years ago

Ah nevermind. I realized you can do .output(:png => String), and then I can base64 encode it with rails. So nevermind. Thx.