Convert image to base64 string with Laravel
In this post we will give you information about Convert image to base64 string with Laravel. Hear we will give you detail about Convert image to base64 string with Laravel And how to use it also give you demo for it if it is necessary.
While developing some projects there could be requirements to store base64 strings instead of the actual image then We need to convert the image to base64 strings. In this short article, We will learn How to convert an image to a base64 string with Laravel. We will cover all possibilities to convert the image to a base64 string in laravel.
Convert image to base64 string with Laravel
Method 1
<?php
namespace AppHttpControllers;
use IlluminateHttpRequest;
class ImageController extends Controller
{
public function store(Request $request){
$image = base64_encode(file_get_contents($request->file('image')->path()));
echo $image;
}
}
Method 2
<?php
namespace AppHttpControllers;
use IlluminateHttpRequest;
class ImageController extends Controller
{
public function store(Request $request){
$image = public_path('storage/banner/15751609757424.jpg');
$base64 = base64_encode(file_get_contents($image));
echo $base64;
}
}
Method 3
<?php
namespace AppHttpControllers;
use IlluminateHttpRequest;
class ImageController extends Controller
{
public function store(Request $request){
$image = $image = storage_path('app/public/banner/15751609757424.jpg');
$base64 = base64_encode(file_get_contents($image));
echo $base64;
}
}
Thank you for reading this blog.
Also see: How to Get Current Route Name in Laravel
. .
Hope this code and post will helped you for implement Convert image to base64 string with Laravel. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs