Skip to content

Commit

Permalink
Make filename optional in render_to_png()
Browse files Browse the repository at this point in the history
In that case, CairoSVG returns a byte string.
  • Loading branch information
SimonSapin committed Nov 30, 2012
1 parent f7bef77 commit 52ca116
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions pygal/ghost.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,7 @@ def render_to_file(self, filename):
with io.open(filename, 'w', encoding='utf-8') as f:
f.write(self.render(is_unicode=True))

def render_to_png(self, filename):
def render_to_png(self, filename=None):
"""Render the graph, convert it to png and write it to filename"""
import cairosvg
from io import BytesIO
fakefile = BytesIO()
fakefile.write(self.render())
fakefile.seek(0)
cairosvg.surface.PNGSurface.convert(
file_obj=fakefile, write_to=filename)
return cairosvg.svg2png(bytestring=self.render(), write_to=filename)

0 comments on commit 52ca116

Please sign in to comment.