Save canvas with external images to local file

守給你的承諾、 提交于 2020-01-15 10:55:07

问题


Is there a way to save to the local filesystem a canvas with loaded images from external websites into it?

If I try with toDataUrl(), it just trhows a Security error. In Firefox I can just save to a file the canvas with the right click, but this is not possible in Chrome.


回答1:


No, for security reasons you can't use toDataUrl().

For why this is happening you need to look into cors.

Here's a bit on why it should be this way.

It's a feature in Firefox that you can right-click save-as because its all local. If it were with toDataUrl() then the webpage could also attempt to send the canvas data to the server and we don't want that.

The right-click save-as is a requested feature in Opera and may come to other browsers someday but I wouldn't bank on the functionality existing any time soon.



来源:https://stackoverflow.com/questions/9656521/save-canvas-with-external-images-to-local-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!