简体   繁体   中英

How to save image in folder ,when you convert binary image to string

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));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM