1

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);
?>
6
  • Set the flag to save full alpha channel information (as opposed to single-color transparency) when saving PNG images Commented Jan 21, 2015 at 10:38
  • Okay... and where in this code are you actually saving the image? Also, why are you getting the image's contents, encoding them, decoding them, and then loading them as a string? Why not just imagecreatefrompng("Logo.png")? Commented Jan 21, 2015 at 10:39
  • Actually i am creating web services for iphone ... iphone user send me data as binary so i am using test image for that.. Commented Jan 21, 2015 at 10:43
  • Okay, so the first two lines are just getting data in the format that your real code will expect. Gotcha. That still doesn't explain where your "save the image" call is. Commented Jan 21, 2015 at 10:44
  • I am not write any code for save image ..i don't understand how to save image in folder Commented Jan 21, 2015 at 10:51

1 Answer 1

6

use file_put_contents

$data = base64_decode($data);

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

or

file_put_contents('img.png', base64_decode($base64string));
Sign up to request clarification or add additional context in comments.

1 Comment

Please repost answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.