如何将html5 Canvas.toDataURl字符串保存为php后端的png [英] How to save a html5 Canvas.toDataURl string as a png on a php backend

查看:383
本文介绍了如何将html5 Canvas.toDataURl字符串保存为php后端的png的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用

将我的画布转换为图片来源后,

  canvas.toDataURL(image / png); 

并将其传递到php文件,如何在服务器上将其另存为.png图像

解决方案

其实很简单,如果你有 allow-url-fopen 。 PHP支持 data: URL scheme,然后自动解码base64和urlencoding。

  preg_match('#^ data:[\w /] +(; [\w =] +)*,[\w + / =%] + $#',$ data = $ _ POST [dataU ])
and
copy($ data,output.png);

但你也可以在并手动 base64_decode() 。 p>

After converting my canvas to a an image source using

 canvas.toDataURL("image/png");

and passing it to a php file, how do I save it as a .png image on the server?

解决方案

It's actually very simple, if you have allow-url-fopen enabled. PHP supports the data: URL scheme then, and automatically decodes base64 and urlencoding.

preg_match('#^data:[\w/]+(;[\w=]+)*,[\w+/=%]+$#', $data=$_POST["dataU"])
and
copy($data, "output.png");

But you could also just extract the part after the , and manually base64_decode() it.

这篇关于如何将html5 Canvas.toDataURl字符串保存为php后端的png的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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