将二进制图像转换为字符串时,如何在文件夹中保存图像

I have tried to convert binary data into an image format and then save this image in a folder. I am using imagesavealpha function but it is not working.

My code is below:

<?php 
$image_data=file_get_contents('Logo.png');
$encoded_image=base64_encode($image_data);
$decoded_image=base64_decode($encoded_image);
$im = imagecreatefromstring($decoded_image);

    header('Content-Type: image/png');
    imagepng($im);
    $fileName ='/image/'.date('ymdhis').'.png'; 

    imagealphablending($im,false); 

    imagesavealpha($im, true);
?>

use file_put_contents

$data = base64_decode($data);

file_put_contents('/tmp/image.png', $data);

or

file_put_contents('img.png', base64_decode($base64string));