public

Create a png alpha image from base 64 data - Stackoverflow snippet (http://stackoverflow.com/questions/9771986/fabric-js-canvas-todataurl-sent-to-php-by-ajax)

  • Download Gist
createPNGAlphaImageFromBase64.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
<?php
$urlUploadImages = '../uploads/img/';
$nameImage = $_POST['nameImage'];
$data = base64_decode($_POST['strBase64']);
$img = imagecreatefromstring($data);
$width = imagesx($img);
$height = imagesy($img);
$image = imagecreatetruecolor($width, $height);
imagealphablending($image, true);
$alpha_image = imagecolorallocatealpha($image, 0, 0, 0, 127);
imagefill($image, 0, 0, $alpha_image);
imagecopyresampled($image, $img, 0, 0, 0, 0, $width, $height, $width, $height);
imagealphablending($image, false);
imagesavealpha($image, true);
header('Content-type: image/png');
imagepng($image, $urlUploadImage.$nameImage, 0);
imagedestroy($img);
?>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.