Published by:
Emil /
Data 3.2.2012 /
Views: 577
// Create new canvas element
var canvas_draw = $('#canvas-draw-fancy');
canvas_draw.width = 320;
canvas_draw.height = 240;
var canvas_draw = $('canvas')[2].getContext('2d');
// Import the image from the old canvas
canvas_draw.drawImage(renderer.domElement, 0, 0, 320, 240);
// Export the image from the canvas
var img = new Image();
img.src = $("canvas")[0].toDataURL('image/png');
img.width = 320;
// Print screens on same page if necesary for preview
document.body.appendChild(img);
// set image data to php
var ajax = new XMLHttpRequest();
ajax.open("POST",'makefile.php',false);
ajax.setRequestHeader('Content-Type', 'application/upload');
ajax.send(img.src);
if (isset($GLOBALS["HTTP_RAW_POST_DATA"]))
{
// Get the data
$imageData=$GLOBALS['HTTP_RAW_POST_DATA'];
// Remove the headers (data:,) part.
// A real application should use them according to needs such as to check image type
$filteredData=substr($imageData, strpos($imageData, ",")+1);
// Need to decode before saving since the data we received is already base64 encoded
$unencodedData=base64_decode($filteredData);
// Save file. This example uses a hard coded filename for testing,
$fp = fopen("images/img_".microtime(1).".png", 'w');
fwrite( $fp, $unencodedData);
fclose( $fp );
}