将原始SVG数据写入python3中的文件?

时间:2016-11-02 21:17:58

标签: python-3.x svg flask wand

到目前为止我有这个代码:

def make_png_download():
svg_data = Graphs.svgdata
with open('chart.svg', 'wb+') as file:
    file.write(svg_data)
    with wand.image.Image(blob=file.read(), format="svg") as image:
        png_image = image.make_blob("png")
    response = send_file(png_image, as_attachment=True, attachment_filename='chart.png')
    response.headers['Content-Description'] = 'Png Download'
    response.headers['Cache-Control'] = 'no-cache'
    response.headers['Content-Type'] = 'image/png'
    response.headers['Content-Disposition'] = 'attachment; filename=chart.png'
    return response

我正在尝试写入一个文件,以便我可以使用wand导入的模块(从svg到png)转换它,但是得到错误' wand.exceptions.BlobError:零长度blob不允许`缓冲区。 SVG' @ error / blob.c / BlobToImage / 343'

我认为这种情况正在发生,因为在尝试写入文件后它是空白的 - 任何人都可以告诉我在这里做错了所以我可以正确地写文件吗?

如果我打印svg_data,它会返回:



b'<?xml version=\'1.0\' encoding=\'utf-8\'?>\n<svg xmlns:xlink="http://www.w3.org/1999/xlink" class="pygal-chart" id="chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958" viewBox="0 0 800 600" xmlns="http://www.w3.org/2000/svg"><!--Generated with pygal 2.2.3 (etree) \xc2\xa9Kozea 2012-2016 on 2016-11-02--><!--http://pygal.org--><!--http://github.com/Kozea/pygal--><defs><style type="text/css">#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958{-webkit-user-select:none;-webkit-font-smoothing:antialiased;font-family:Yuppy SC,bold}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .title{font-family:Yuppy SC;font-size:25px}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .legends .legend text{font-family:Yuppy SC;font-size:14px}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .axis text{font-family:Yuppy SC;font-size:16px}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .axis text.major{font-family:Yuppy SC,bold;font-size:16px}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .text-overlay text.value{font-family:Yuppy SC,bold;font-size:22px}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .text-overlay text.label{font-family:Yuppy SC,bold;font-size:20px}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .tooltip{font-family:Yuppy SC;font-size:20px}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 text.no_data{font-family:Yuppy SC,bold;font-size:64px}\n#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958{background-color:transparent}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 path,#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 line,#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 rect,#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 circle{-webkit-transition:400ms ease-in;-moz-transition:400ms ease-in;transition:400ms ease-in}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .graph &gt; .background{fill:transparent}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .plot &gt; .background{fill:white}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .graph{fill:#555555}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 text.no_data{fill:#555555}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .title{fill:#555555}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .legends .legend text{fill:#555555}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .legends .legend:hover text{fill:#555555}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .axis .line{stroke:#555555}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .axis .guide.line{stroke:#555555}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .axis .major.line{stroke:#555555}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .axis text.major{fill:#555555}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .axis.y .guides:hover .guide.line,#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .line-graph .axis.x .guides:hover .guide.line,#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .stackedline-graph .axis.x .guides:hover .guide.line,#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .xy-graph .axis.x .guides:hover .guide.line{stroke:#555555}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .axis .guides:hover text{fill:#555555}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .reactive{fill-opacity:.7;stroke-opacity:.8}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .ci{stroke:#555555}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .reactive.active,#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .active .reactive{fill-opacity:.9;stroke-opacity:.9;stroke-width:4}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .ci .reactive.active{stroke-width:1.5}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .series text{fill:#555555}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .tooltip rect{fill:white;stroke:#555555;-webkit-transition:opacity 400ms ease-in;-moz-transition:opacity 400ms ease-in;transition:opacity 400ms ease-in}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .tooltip .label{fill:#555555}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .tooltip .label{fill:#555555}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .tooltip .legend{font-size:.8em;fill:#555555}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .tooltip .x_label{font-size:.6em;fill:#555555}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .tooltip .xlink{font-size:.5em;text-decoration:underline}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .tooltip .value{font-size:1.5em}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .bound{font-size:.5em}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .max-value{font-size:.75em;fill:#555555}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .map-element{fill:white;stroke:#555555 !important}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .map-element .reactive{fill-opacity:inherit;stroke-opacity:inherit}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .color-0,#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .color-0 a:visited{stroke:#7bb025;fill:#7bb025}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .color-1,#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .color-1 a:visited{stroke:#f37400;fill:#f37400}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .color-2,#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .color-2 a:visited{stroke:#3596bd;fill:#3596bd}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .color-3,#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .color-3 a:visited{stroke:#c73b3a;fill:#c73b3a}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .color-4,#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .color-4 a:visited{stroke:#ac99a0;fill:#ac99a0}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .color-5,#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .color-5 a:visited{stroke:#df983e;fill:#df983e}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .color-6,#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .color-6 a:visited{stroke:#ffc208;fill:#ffc208}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .color-7,#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .color-7 a:visited{stroke:#d0551b;fill:#d0551b}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .color-8,#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .color-8 a:visited{stroke:#db160b;fill:#db160b}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .color-9,#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .color-9 a:visited{stroke:#3575db;fill:#3575db}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .color-10,#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .color-10 a:visited{stroke:#1a2508;fill:#1a2508}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .color-11,#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .color-11 a:visited{stroke:#4b2400;fill:#4b2400}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .color-12,#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .color-12 a:visited{stroke:#102e3a;fill:#102e3a}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .text-overlay .color-0 text{fill:black}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .text-overlay .color-1 text{fill:black}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .text-overlay .color-2 text{fill:black}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .text-overlay .color-3 text{fill:black}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .text-overlay .color-4 text{fill:black}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .text-overlay .color-5 text{fill:black}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .text-overlay .color-6 text{fill:black}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .text-overlay .color-7 text{fill:black}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .text-overlay .color-8 text{fill:black}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .text-overlay .color-9 text{fill:black}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .text-overlay .color-10 text{fill:white}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .text-overlay .color-11 text{fill:white}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .text-overlay .color-12 text{fill:white}\n#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 text.no_data{text-anchor:middle}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .guide.line{fill:none}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .centered{text-anchor:middle}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .title{text-anchor:middle}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .legends .legend text{fill-opacity:1}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .axis.x text{text-anchor:middle}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .axis.x:not(.web) text[transform]{text-anchor:start}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .axis.x:not(.web) text[transform].backwards{text-anchor:end}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .axis.y text{text-anchor:end}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .axis.y text[transform].backwards{text-anchor:start}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .axis.y2 text{text-anchor:start}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .axis.y2 text[transform].backwards{text-anchor:end}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .axis .guide.line{stroke-dasharray:4,4}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .axis .major.guide.line{stroke-dasharray:6,6}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .horizontal .axis.y .guide.line,#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .horizontal .axis.y2 .guide.line,#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .vertical .axis.x .guide.line{opacity:0}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .horizontal .axis.always_show .guide.line,#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .vertical .axis.always_show .guide.line{opacity:1 !important}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .axis.y .guides:hover .guide.line,#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .axis.y2 .guides:hover .guide.line,#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .axis.x .guides:hover .guide.line{opacity:1}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .axis .guides:hover text{opacity:1}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .nofill{fill:none}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .subtle-fill{fill-opacity:.2}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .dot{stroke-width:1px;fill-opacity:1}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .dot.active{stroke-width:5px}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .dot.negative{fill:transparent}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 text,#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 tspan{stroke:none !important}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .series text.active{opacity:1}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .tooltip rect{fill-opacity:.95;stroke-width:.5}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .tooltip text{fill-opacity:1}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .showable{visibility:hidden}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .showable.shown{visibility:visible}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .gauge-background{fill:rgba(229,229,229,1);stroke:none}#chart-1d0a0c14-5022-4e9e-b1a7-698ffda55958 .bg-lines{stroke:transparent;stroke-width:2px}</style><script type="text/javascript">window.pygal = window.pygal || {};window.pygal.config = window.pygal.config || {};window.pygal.config[\'1d0a0c14-5022-4e9e-b1a7-698ffda55958\'] = {"inner_radius": 0.3, "dynamic_print_values": false, "interpolation_precision": 250, "tooltip_border_radius": 0, "legend_at_bottom": false, "margin_top": null, "print_zeroes": true, "stroke": true, "x_labels": null, "height": 600, "logarithmic": false, "pretty_print": false, "tooltip_fancy_mode": true, "margin_right": null, "xrange": null, "allow_interruptions": false, "interpolation_parameters": {}, "show_x_guides": false, "x_title": null, "style": {"label_font_size": 16, "title_font_family": "Yuppy SC", "background": "transparent", "no_data_font_family": "Yuppy SC, bold", "value_background": "rgba(229, 229, 229, 1)", "stroke_opacity_hover": ".9", "ci_colors": [], "tooltip_font_size": 20, "stroke_opacity": ".8", "guide_stroke_dasharray": "4,4", "legend_font_family": "Yuppy SC", "foreground": "#555555", "transition": "400ms ease-in", "major_guide_stroke_dasharray": "6,6", "opacity_hover": ".9", "foreground_strong": "#555555", "value_label_font_size": 20, "major_label_font_size": 16, "value_colors": [], "value_font_size": 22, "opacity": ".7", "value_font_family": "Yuppy SC, bold", "tooltip_font_family": "Yuppy SC", "major_label_font_family": "Yuppy SC, bold", "value_label_font_family": "Yuppy SC, bold", "font_family": "Yuppy SC, bold", "legend_font_size": 14, "title_font_size": 25, "label_font_family": "Yuppy SC", "foreground_subtle": "#555555", "colors": ["#7BB025", "#F37400", "#3596BD", "#C73B3A", "#AC99A0", "#DF983E", "#FFC208", "#D0551B", "#DB160B", "#3575DB"], "no_data_font_size": 64, "plot_background": "white"}, "force_uri_protocol": "https", "disable_xml_declaration": false, "css": ["file://style.css", "file://graph.css"], "print_values": false, "x_labels_major_count": null, "explicit_size": false, "y_labels": null, "fill": false, "legends": ["Frames", "Cards", "Gifts", "Frontiers", "Supply Chain &amp; Logistics", "WH", "Poli", "Wall Decor", "Canvas", "Prints", "Logistics", "Mugs", "3D Sublimation"], "width": 800, "no_prefix": false, "stroke_style": null, "margin": 20, "x_labels_major": null, "defs": [], "y_title": null, "margin_bottom": null, "print_values_position": "center", "show_y_labels": true, "range": null, "interpolate": null, "max_scale": 16, "y_labels_major_count": null, "order_min": null, "dots_size": 2.5, "y_label_rotation": 0, "y_labels_major": null, "title": "Precentage of Absence per Team (%)", "x_label_rotation": 0, "classes": ["pygal-chart"], "truncate_legend": null, "missing_value_fill_truncation": "x", "show_x_labels": true, "show_minor_x_labels": true, "strict": false, "show_dots": true, "x_labels_major_every": null, "secondary_range": null, "box_mode": "extremes", "rounded_bars": null, "show_y_guides": true, "zero": 0, "no_data_text": "No data", "half_pie": false, "inverse_y_axis": false, "margin_left": null, "formatter": null, "stack_from_top": false, "min_scale": 4, "spacing": 10, "y_labels_major_every": null, "legend_box_size": 22, "show_only_major_dots": false, "print_labels": false, "include_x_axis": false, "js": ["//kozea.github.io/pygal.js/2.0.x/pygal-tooltips.min.js"], "truncate_label": null, "legend_at_bottom_columns": null, "show_minor_y_labels": true, "show_legend": true}</script><script type="text/javascript" xlink:href="https://kozea.github.io/pygal.js/2.0.x/pygal-tooltips.min.js" /></defs><title>Precentage of Absence per Team (%)</title><g class="graph pie-graph vertical"><rect class="background" height="600" width="800" x="0" y="0" /><g class="plot" transform="translate(178, 55)"><rect class="background" height="525" width="602.0" x="0" y="0" /><g class="series serie-0 color-0"><g class="slices"><g class="slice"><a xlink:href="http://127.0.0.1:4996/download-chart"><desc class="xlink">http://127.0.0.1:4996/download-chart</desc><path class="slice reactive tooltip-trigger" d="M301.000000 26.250000 A236.250000 236.250000 0 0 1 359.280948 33.551548 L320.426983 186.183849 A78.750000 78.750000 0 0 0 301.000000 183.750000 z" /><desc class="value">1.13%</desc><desc class="x centered">320.5788477886972</desc><desc class="y centered">106.22166266795955</desc></a></g></g></g><g class="series serie-1 color-1"><g class="slices"><g class="slice"><a xlink:href="http://127.0.0.1:4996/download-chart"><desc class="xlink">http://127.0.0.1:4996/download-chart</desc><path class="slice reactive tooltip-trigger" d="M359.280948 33.551548 A236.250000 236.250000 0 0 1 446.565071 76.422402 L349.521690 200.474134 A78.750000 78.750000 0 0 0 320.426983 186.183849 z" /><desc class="value">1.88%</desc><desc class="x centered">370.43510932052936</desc><desc class="y centered">121.13163156615926</desc></a></g></g></g><g class="series serie-2 color-2"><g class="slices"><g class="slice"><a xlink:href="http://127.0.0.1:4996/download-chart"><desc class="xlink">http://127.0.0.1:4996/download-chart</desc><path class="slice reactive tooltip-trigger" d="M446.565071 76.422402 A236.250000 236.250000 0 0 1 482.918572 111.769461 L361.639524 212.256487 A78.750000 78.750000 0 0 0 349.521690 200.474134 z" /><desc class="value">0.975%</desc><desc class="x centered">410.7952393652246</desc><desc class="y centered">149.57854316945327</desc></a></g></g></g><g class="series serie-3 color-3"><g class="slices"><g class="slice"><a xlink:href="http://127.0.0.1:4996/download-chart"><desc class="xlink">http://127.0.0.1:4996/download-chart</desc><path class="slice reactive tooltip-trigger" d="M482.918572 111.769461 A236.250000 236.250000 0 0 1 513.533884 159.333092 L371.844628 228.111031 A78.750000 78.750000 0 0 0 361.639524 212.256487 z" /><desc class="value">1.09%</desc><desc class="x centered">433.4365839963262</desc><desc class="y centered">177.25446510588347</desc></a></g></g></g><g class="series serie-4 color-4"><g class="slices"><g class="slice"><a xlink:href="http://127.0.0.1:4996/download-chart"><desc class="xlink">http://127.0.0.1:4996/download-chart</desc><path class="slice reactive tooltip-trigger" d="M513.533884 159.333092 A236.250000 236.250000 0 0 1 533.929875 223.031840 L378.643292 249.343947 A78.750000 78.750000 0 0 0 371.844628 228.111031 z" /><desc class="value">1.29%</desc><desc class="x centered">450.9983300131739</desc><desc class="y centered">214.4713523690395</desc></a></g></g></g><g class="series serie-5 color-5"><g class="slices"><g class="slice"><a xlink:href="http://127.0.0.1:4996/download-chart"><desc class="xlink">http://127.0.0.1:4996/download-chart</desc><path class="slice reactive tooltip-trigger" d="M533.929875 223.031840 A236.250000 236.250000 0 0 1 370.946735 488.157964 L324.315578 337.719321 A78.750000 78.750000 0 0 0 378.643292 249.343947 z" /><desc class="value">6.52%</desc><desc class="x centered">435.17488697510225</desc><desc class="y centered">344.9824205829251</desc></a></g></g></g><g class="series serie-6 color-6"><g class="slices"><g class="slice"><a xlink:href="http://127.0.0.1:4996/download-chart"><desc class="xlink">http://127.0.0.1:4996/download-chart</desc><path class="slice reactive tooltip-trigger" d="M370.946735 488.157964 A236.250000 236.250000 0 0 1 291.481953 498.558190 L297.827318 341.186063 A78.750000 78.750000 0 0 0 324.315578 337.719321 z" /><desc class="value">1.55%</desc><desc class="x centered">321.43904510959067</desc><desc class="y centered">418.6681639611868</desc></a></g></g></g><g class="series serie-7 color-7"><g class="slices"><g class="slice"><a xlink:href="http://127.0.0.1:4996/download-chart"><desc class="xlink">http://127.0.0.1:4996/download-chart</desc><path class="slice reactive tooltip-trigger" d="M291.481953 498.558190 A236.250000 236.250000 0 0 1 183.863235 467.665886 L261.954412 330.888629 A78.750000 78.750000 0 0 0 297.827318 341.186063 z" /><desc class="value">2.17%</desc><desc class="x centered">257.5440506857186</desc><desc class="y centered">413.8863615693125</desc></a></g></g></g><g class="series serie-8 color-8"><g class="slices"><g class="slice"><a xlink:href="http://127.0.0.1:4996/download-chart"><desc class="xlink">http://127.0.0.1:4996/download-chart</desc><path class="slice reactive tooltip-trigger" d="M183.863235 467.665886 A236.250000 236.250000 0 0 1 97.052895 381.746135 L233.017632 302.248712 A78.750000 78.750000 0 0 0 261.954412 330.888629 z" /><desc class="value">2.37%</desc><desc class="x centered">190.20637043159743</desc><desc class="y centered">374.44204593029195</desc></a></g></g></g><g class="series serie-9 color-9"><g class="slices"><g class="slice"><a xlink:href="http://127.0.0.1:4996/download-chart"><desc class="xlink">http://127.0.0.1:4996/download-chart</desc><path class="slice reactive tooltip-trigger" d="M97.052895 381.746135 A236.250000 236.250000 0 0 1 65.452254 280.702248 L222.484085 268.567416 A78.750000 78.750000 0 0 0 233.017632 302.248712 z" /><desc class="value">2.05%</desc><desc class="x centered">150.67975242492986</desc><desc class="y centered">309.5114153048982</desc></a></g></g></g><g class="series serie-10 color-10"><g class="slices"><g class="slice"><a xlink:href="http://127.0.0.1:4996/download-chart"><desc class="xlink">http://127.0.0.1:4996/download-chart</desc><path class="slice reactive tooltip-trigger" d="M65.452254 280.702248 A236.250000 236.250000 0 0 1 70.070074 212.645894 L224.023358 245.881965 A78.750000 78.750000 0 0 0 222.484085 268.567416 z" /><desc class="value">1.31%</desc><desc class="x centered">143.86131899861402</desc><desc class="y centered">251.83768631371902</desc></a></g></g></g><g class="series serie-11 color-11"><g class="slices"><g class="slice"><a xlink:href="http://127.0.0.1:4996/download-chart"><desc class="xlink">http://127.0.0.1:4996/download-chart</desc><path class="slice reactive tooltip-trigger" d="M70.070074 212.645894 A236.250000 236.250000 0 0 1 267.142625 28.688664 L289.714208 184.562888 A78.750000 78.750000 0 0 0 224.023358 245.881965 z" /><desc class="value">5.51%</desc><desc class="x centered">193.52774154611257</desc><desc class="y centered">147.36545408600935</desc></a></g></g></g><g class="series serie-12 color-12"><g class="slices"><g class="slice"><a xlink:href="http://127.0.0.1:4996/download-chart"><desc class="xlink">http://127.0.0.1:4996/download-chart</desc><path class="slice reactive tooltip-trigger" d="M267.142625 28.688664 A236.250000 236.250000 0 0 1 301.000000 26.250000 L301.000000 183.750000 A78.750000 78.750000 0 0 0 289.714208 184.562888 z" /><desc class="value">0.652%</desc><desc class="x centered">289.68497101008614</desc><desc class="y centered">105.40696985875724</desc></a></g></g></g></g><g class="titles"><text class="title plot_title" x="400.0" y="35">Precentage of Absence per Team (%)</text></g><g class="plot overlay" transform="translate(178, 55)"><g class="series serie-0 color-0" /><g class="series serie-1 color-1" /><g class="series serie-2 color-2" /><g class="series serie-3 color-3" /><g class="series serie-4 color-4" /><g class="series serie-5 color-5" /><g class="series serie-6 color-6" /><g class="series serie-7 color-7" /><g class="series serie-8 color-8" /><g class="series serie-9 color-9" /><g class="series serie-10 color-10" /><g class="series serie-11 color-11" /><g class="series serie-12 color-12" /></g><g class="plot text-overlay" transform="translate(178, 55)"><g class="series serie-0 color-0" /><g class="series serie-1 color-1" /><g class="series serie-2 color-2" /><g class="series serie-3 color-3" /><g class="series serie-4 color-4" /><g class="series serie-5 color-5" /><g class="series serie-6 color-6" /><g class="series serie-7 color-7" /><g class="series serie-8 color-8" /><g class="series serie-9 color-9" /><g class="series serie-10 color-10" /><g class="series serie-11 color-11" /><g class="series serie-12 color-12" /></g><g class="plot tooltip-overlay" transform="translate(178, 55)"><g class="tooltip" style="opacity: 0" transform="translate(0 0)"><rect class="tooltip-box" height="0" rx="0" ry="0" width="0" /><g class="text" /></g></g><g class="legends" transform="translate(10, 65)"><g class="legend reactive activate-serie" id="activate-serie-0"><rect class="color-0 reactive" height="22" width="22" x="0.0" y="0.0" /><text x="27.0" y="15.2">Frames</text></g><g class="legend reactive activate-serie" id="activate-serie-1"><rect class="color-1 reactive" height="22" width="22" x="0.0" y="33.0" /><text x="27.0" y="48.2">Cards</text></g><g class="legend reactive activate-serie" id="activate-serie-2"><rect class="color-2 reactive" height="22" width="22" x="0.0" y="66.0" /><text x="27.0" y="81.2">Gifts</text></g><g class="legend reactive activate-serie" id="activate-serie-3"><rect class="color-3 reactive" height="22" width="22" x="0.0" y="99.0" /><text x="27.0" y="114.2">Frontiers</text></g><g class="legend reactive activate-serie" id="activate-serie-4"><rect class="color-4 reactive" height="22" width="22" x="0.0" y="132.0" /><text x="27.0" y="147.2">Supply Chain &amp;\xe2\x80\xa6</text><title>Supply Chain &amp; Logistics</title></g><g class="legend reactive activate-serie" id="activate-serie-5"><rect class="color-5 reactive" height="22" width="22" x="0.0" y="165.0" /><text x="27.0" y="180.2">WH</text></g><g class="legend reactive activate-serie" id="activate-serie-6"><rect class="color-6 reactive" height="22" width="22" x="0.0" y="198.0" /><text x="27.0" y="213.2">Poli</text></g><g class="legend reactive activate-serie" id="activate-serie-7"><rect class="color-7 reactive" height="22" width="22" x="0.0" y="231.0" /><text x="27.0" y="246.2">Wall Decor</text></g><g class="legend reactive activate-serie" id="activate-serie-8"><rect class="color-8 reactive" height="22" width="22" x="0.0" y="264.0" /><text x="27.0" y="279.2">Canvas</text></g><g class="legend reactive activate-serie" id="activate-serie-9"><rect class="color-9 reactive" height="22" width="22" x="0.0" y="297.0" /><text x="27.0" y="312.2">Prints</text></g><g class="legend reactive activate-serie" id="activate-serie-10"><rect class="color-0 reactive" height="22" width="22" x="0.0" y="330.0" /><text x="27.0" y="345.2">Logistics</text></g><g class="legend reactive activate-serie" id="activate-serie-11"><rect class="color-1 reactive" height="22" width="22" x="0.0" y="363.0" /><text x="27.0" y="378.2">Mugs</text></g><g class="legend reactive activate-serie" id="activate-serie-12"><rect class="color-2 reactive" height="22" width="22" x="0.0" y="396.0" /><text x="27.0" y="411.2">3D Sublimation</text></g></g><g class="legends" transform="translate(790, 65)" /></g></svg>'
&#13;
&#13;
&#13;

wand.image.Image(blob =)需要一个bytearray / bytes类型的对象,我认为这是原始svg内容所必需的,因此我打开了&#39; wb +&#39;使用open()上下文管理器的权限,但也许这在某种程度上是错误的?
我还尝试使用file.write(svg_data.encode(&#39; utf-8&#39;)写入文件时将数据编码为utf-8,但这似乎也不起作用。

编辑:

def make_png_download():
svg_data = Graphs.svgdata
with open('chart.svg', 'wb+') as file:
    file.write(svg_data)
with open(file, 'rb') as rfile:
    with wand.image.Image(blob=rfile.read(), format="svg") as image:
        png_image = image.make_blob("png")
    response = send_file(png_image, as_attachment=True, attachment_filename='chart.png')

0 个答案:

没有答案