Posts Learn Components Snippets Categories Tags 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 }}">

Snippets by

PostSrc poster


Full stack developer mainly focusing on the front end side of the web. The main author of PostSrc and loves writing tutorial and guides online.


PostSrc Code Components

Collection of Tailwind CSS components for everyone to use. Browse all of the components that's right for your project.

View Components

Other Code Snippets