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

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...