I should have done this recently.
First, I put canvasData in a hidden field and placed it on my PHP page.
It returns in this format: data:image/png;base64,iVBORw0......
First you need to break the data, as this is: data:image/png;base64, is the header information. The rest is encoded data.
$rawData = $_POST['imageData']; $filteredData = explode(',', $rawData); $unencoded = base64_decode($filteredData[1]);
Then I create an image on my server:
//Create the image $fp = fopen('sigs/test1.png', 'w'); fwrite($fp, $unencoded); fclose($fp);
And then read it to do whatever I want.
$file_name = 'test1.png'; $file_size = strlen($filteredData[1])/1024; //This may be wrong, doesn't seem to break for me though. $fh = fopen('sigs/test1.png', 'r'); $content = fread($fh, $file_size); $content = base64_encode($content); fclose($fh);
I am more than sure that there is a much more elegant solution, but it works for me!
Check this out for more info (maybe): My own question
source share