Last active
June 8, 2017 22:11
-
-
Save rodrigopandini/2149853 to your computer and use it in GitHub Desktop.
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment