Skip to content

Instantly share code, notes, and snippets.

@s-hiroshi

s-hiroshi/example.js

Created Nov 25, 2012
Embed
What would you like to do?
JavaScript > snippets > Canvasデーターの保存
jQuery(function($) {
// body部パラメーター
var data = {};
// Canvasのデータをbase64でエンコードした文字列を取得
var canvasData = $('canvas').get(0).toDataURL();
// 不要な情報を取り除く
canvasData = canvasData.replace(/^data:image\/png;base64,/, '');
data.image = canvasData;
$.ajax({
url: 'example.php',
type: 'POST',
success: function() {
// 成功時の処理
},
error(jqXHR, textStatus, errorThrown) {
// 失敗時の処理
},
data: data,
dataType: 'json'
});
});
<?php
$imageData = $_POST['image'];
$filename = 'example.png';
$fp = fopen(, 'w');
fwrite($fp,base64_decode($imageData));
fclose($fp);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.