如何将 svg 画布保存到本地文件系统 [英] How to save svg canvas to local filesystem

查看:49
本文介绍了如何将 svg 画布保存到本地文件系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法允许用户在使用浏览器在 javascript svg 画布上创建矢量图后,将此文件下载到他们的本地文件系统?

Is there a way to allow a user, after he has created a vector graph on a javascript svg canvas using a browser, to download this file to their local filesystem?

SVG 对我来说是一个全新的领域,所以如果我的措辞不准确,请耐心等待.

SVG is a total new field for me so please be patient if my wording is not accurate.

推荐答案

可能可以使用常规的保存"浏览器命令,但它不仅会保存 SVG 画布,还会保存整个页面.

It might be possible using the regular "Save" browser command, but it won't just save the SVG canvas, it will save the whole page.

我相信您最好的选择是使用 AJAX 并将整个 SVG XML 数据作为 POST 数据发送到服务器脚本,并让该脚本仅将带有标题的 POST 数据发送回 Content-Disposition: attachment;文件名=您的文件.svg.

I believe your best bet is to use AJAX and send the whole SVG XML data as POST data to a server script, and have that script just send back the POST data with the header Content-Disposition: attachment; filename=yourfile.svg.

(在 PHP 下,您可以使用 file_get_contents('php://input') 获取原始 POST 内容.)

(Under PHP, you can get the raw POST contents with file_get_contents('php://input').)

这篇关于如何将 svg 画布保存到本地文件系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆