9

I'm trying to save image encoded by base64 using Intervention Image, laravel-5 Exception told me that "Unable to init from given binary data". anyone can help?

$png_url = "user-".time().".png";
$path = "/public/".$png_url;
Image::make(base64_encode($request['image']))->save($path);

2 Answers 2

5
<?php
$png_url = "user-".time().".png";
$path = "/public/".$png_url;
$base=base64_decode($request['image']);
Image::make($base)->save($path);
?>
Sign up to request clarification or add additional context in comments.

2 Comments

Isn't this the same thing as listed in the original question?
No, the OP was using base64_encode(), the answer is base64_decode()
1

if your code works well on your localhost and you upload to a live server and you experience such error its sometimes caused by the path issue on windows server and ubuntu/etc servers.

In my case i changed all the \ in my path to /

That is:

Image::make(base64_decode($request['profile_pic']))->save(public_path('cdn\profile_pictures\/'.$imageName))->destroy();

to

Image::make(base64_decode($request['profile_pic']))->save(public_path('cdn/profile_pictures//'.$imageName))->destroy();

Hope this helps someone...Happy coding...

Comments

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.