1

I am working on an API for mobile application, from mobile end I'm getting the image in base64 format and inserting it in profile_image column in my database.

In my web I want to display that image, so how do I decode it:

<div class="card horizontal card-driver-details">
    <div class="card-image card-circular">
        <img src="{{ $driver->profile_image}} "> //i want to display here
    </div>
    <div class="card-stacked">
        <div class="card-content">
            <p><b>Name:</b>{{ $driver->first_name }} {{ $driver->last_name }}</p>
            <p><b>Phone:</b>{{ $driver->phone_number }}</p>
            <p><b>Address:</b>{{ $driver->addess_city_village }} {{ $driver->address_state }}</p>
        </div>
    </div>
</div>
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Mr Robot
  • 887
  • 4
  • 18
  • 47
  • 1
    and what have you **tried yourself** so far? perhaps asking [search engine of your choice] for something among the lines of "html img base64"? (related: https://stackoverflow.com/questions/1207190/embedding-base64-images ) – Franz Gleichmann Jan 17 '17 at 06:21

6 Answers6

2

Try

base64_decode($driver->profile_image);
Muhammad Hassaan
  • 7,296
  • 6
  • 30
  • 50
2

Try this one.

{{ base64_decode($driver->profile_image) }}

This will decode the profile_image using base 64 and then print the results.

Arun Code
  • 1,548
  • 1
  • 13
  • 18
2

All types of file can be solved by using this ,

  $image_64 = $data['photo_url']; //your base64 encoded data

  $extension = explode('/', explode(':', substr($image_64, 0, strpos($image_64, ';')))[1])[1];   // .jpg .png .pdf

  $replace = substr($image_64, 0, strpos($image_64, ',')+1); 

// find substring fro replace here eg: data:image/png;base64,

 $image = str_replace($replace, '', $image_64); 

 $image = str_replace(' ', '+', $image); 

 $imageName = Str::random(10).'.'.$extension;

 Storage::disk('public')->put($imageName, base64_decode($image));
basith
  • 21
  • 1
  • 1
1

Try this:

$image = base64_decode('base_64_image_string');
$fp = fopen('path_to_where_you_want_to_save_image','wb+');
fwrite($fp,$image);
fclose($fp);
Mayank Pandeyz
  • 25,704
  • 4
  • 40
  • 59
0

i tried with the following code but din't work

base64_decode($driver->profile_image);

then did some browsing about this then find out now all the updated browser support data:image/jpeg/png/gif/etc

so now i am able to display the image

$driver->profile_image
Mr Robot
  • 887
  • 4
  • 18
  • 47
0

To show a base64 converted image in Laravel 10 this works for me.

<img src="data:image/png;base64,{{ $product->image }}" >
ENU ENAN
  • 151
  • 1
  • 5