微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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);

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐