diff options
author | Ian Weller <ianweller@gmail.com> | 2008-09-29 00:16:37 -0500 |
---|---|---|
committer | Ian Weller <ianweller@gmail.com> | 2008-09-29 00:16:37 -0500 |
commit | 8474b9a4ee0eb8dc51de3b8fe4993272f4d7beb6 (patch) | |
tree | 617fa19bc444f083de7361dd61f97777c543a549 /fedora_business_cards/export.py | |
parent | 2d7cffd750006341895d2f20dfa2b4892c421714 (diff) | |
download | fedora-business-cards-8474b9a4ee0eb8dc51de3b8fe4993272f4d7beb6.tar.gz fedora-business-cards-8474b9a4ee0eb8dc51de3b8fe4993272f4d7beb6.tar.xz fedora-business-cards-8474b9a4ee0eb8dc51de3b8fe4993272f4d7beb6.zip |
Change svg_to_pdf_png, add card editing
Diffstat (limited to 'fedora_business_cards/export.py')
-rw-r--r-- | fedora_business_cards/export.py | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/fedora_business_cards/export.py b/fedora_business_cards/export.py index d4b6c37..5d3d922 100644 --- a/fedora_business_cards/export.py +++ b/fedora_business_cards/export.py @@ -25,6 +25,7 @@ Functions to export cards from SVGs. import rsvg import cairo +from StringIO import StringIO if not cairo.HAS_PDF_SURFACE: raise SystemExit('cairo was not compiled with PDF support') @@ -32,21 +33,25 @@ if not cairo.HAS_PNG_FUNCTIONS: raise SystemExit('cairo was not compiled with PNG support') -def svg_to_pdf_png(pdfname, pngname, xmlstring, dpi=300): +def svg_to_pdf_png(xmlstring, filename, format='png', dpi=300): """ - Export an SVG to both a PDF and PNG. - pngname = location of PNG file to export to - pdfname = location of pdf file to export to + Export an SVG to either a PDF or PNG. xmlstring = the SVG XML to export + filename = name of file to save as + format = either 'png' or 'pdf' dpi = DPI to export PNG with (default: 300) """ svg = rsvg.Handle(data=xmlstring) - pdffile = file(pdfname, 'w') + if format == "pdf": + pdffile = file(filename, 'w') + else: + pdffile = StringIO() width = int(svg.props.width/90.*dpi) height = int(svg.props.height/90.*dpi) surface = cairo.PDFSurface(pdffile, width, height) ctx = cairo.Context(surface) svg.render_cairo(ctx) - surface.write_to_png(pngname) + if format == "png": + surface.write_to_png(filename) surface.finish() pdffile.close() |