I know this can be done in pure PHP but could not find the solution.
Here is what I have so far:
<?php
// posted canvas image data (string), such as:
// "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAArcAAAHbCAYAAADRQ7"
$data = $_POST['data'];
// remove the "data:image/png;base64," part
$uri = substr($data,strpos($data,",")+1);
$imgData = base64_decode($uri);
// NOT WORKING: transparent to white pixels
$im = imagecreatefromstring($imgData);
$white = imagecolorallocate($im, 255, 255, 255);
imagefill($im, 0, 0, $white);
// END NOT WORKING
// put the data to a file
file_put_contents('yourimage.png', $imgData);
// force user to download the image
if(file_exists('yourimage.png')){
// save dialog box
header('Content-Disposition: attachment; filename="yourimage.png"');
// output png format
header('Content-type: image/png');
// read from server and write to buffer
readfile('yourimage.png');
}
?>
First I tried to find out if PHP can change the image/png-String directly and modify the transparent parts, but could not find anything. Now I try to create an image from the posted string, and fail as well...
Any help appreciated.