加入收藏 | 设为首页 | 会员中心 | 我要投稿 安卓应用网 (https://www.0791zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > PHP > 正文

php如何将HTML5 Canvas保存为服务器上的图像

发布时间:2020-05-25 02:31:43 所属栏目:PHP 来源:互联网
导读:本文章向大家介绍php如何将HTML5 Canvas保存为服务器上的图像,需要的朋友可以参考一下。

以下是如何实现您的需求的示例:

1)画一些东西(取自画布教程)

2)将画布图像转换为URL格式(base64)

var dataURL = canvas.toDataURL();

3)通过Ajax将其发送到您的服务器

$.ajax({

type: "POST",

url: "script.php",

data: {

imgBase64: dataURL

}

}).done(function(o) {

console.log('saved');

// If you want the file to be visible in the browser

// - please modify the callback in javascript. All you

// need is to return the url to the file,you just saved

// and than put the image in your browser.

});

3)将base64保存在服务器上作为图像

$img = $_POST['data'];

$img = str_replace('data:image/png;base64,','',$img);

$img = str_replace(' ','+',$img);

$fileData = base64_decode($img);

//saving

$fileName = 'photo.png';

file_put_contents($fileName,$fileData);

(编辑:安卓应用网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读