Posts Learn Components Snippets Categories Tags Tools new About

Intervention Image encode image to base64 format in Laravel

Learn how to encode image in Intervention image to get a base64 encoded alue

Created on Aug 22, 2021


To encode an image to base64 format in Laravel you can make use Intervention Image package.

Intervention Image

By using the Intervention Image package, you can call out the "encode()" method and pass in the "data-url" as the parameter to get the base64 value.

From the Laravel disk you can retrieve the image and pass it on to the Intervention Image "make()" method like below.

use Intervention\Image\Facades\Image;

$userPosterImage = User::first()

$imageLocation = \Storage::disk('public')

$imageInBase64 = (string) Image::make($imageLocation)
Now that you have the image in base64 format you can pass it to the image tag and preview it on your browser.
<img src="{{ $imageInBase64 }}">

If you like our tutorial, do make sure to support us by being our Patreon or buy us some coffee ☕️