You can use below code with option of saving an image and resizing saved png image without losing its transparent/white effect :
$data = 'binary data of image';
$data = base64_decode($data);
$im = imagecreatefromstring($data);
// assign new width/height for resize purpose
$newwidth = $newheight = 50;
// Create a new image from the image stream in the string
$thumb = imagecreatetruecolor($newwidth, $newheight);
if ($im !== false) {
// Select the HTTP-Header for the selected filetype
#header('Content-Type: image/png'); // uncomment this code to display image in browser
// alter or save the image
$fileName = $_SERVER['DOCUMENT_ROOT'].'server location to store image/'.date('ymdhis').'.png'; // path to png image
imagealphablending($im, false); // setting alpha blending on
imagesavealpha($im, true); // save alphablending setting (important)
// Generate image and print it
$resp = imagepng($im, $fileName);
// resizing png file
imagealphablending($thumb, false); // setting alpha blending on
imagesavealpha($thumb, true); // save alphablending setting (important)
$source = imagecreatefrompng($fileName); // open image
imagealphablending($source, true); // setting alpha blending on
list($width, $height, $type, $attr) = getimagesize($fileName);
#echo '<br>' . $width . '-' . $height . '-' . $type . '-' . $attr . '<br>';
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
$newFilename = $_SERVER['DOCUMENT_ROOT'].'server location to store image/resize_'.date('ymdhis').'.png';
$resp = imagepng($thumb,$newFilename);
// frees image from memory
imagedestroy($im);
imagedestroy($thumb);
}
else {
echo 'An error occurred.';
}
Same way, we can do for JPEG, JPG and GIF format of images.
Hope it helps to people here!