Intervention Image - save to variable in base64 encoded format

Limon Monte picture Limon Monte · Nov 7, 2015 · Viewed 13.8k times · Source

I'm using Laravel with image manipulating package Intervention Image.

I want to save cropped image to variable and then to DB but can't find in documentation how to export result as string. Here's my code:

$img = Image::make($uploadedImage);
$img->crop(160, 210);
$imageEncoded = // ?

There's save(), but it only saves to file.

How can I export modified Intervention Image to string variable? (data:image/jpeg;base64,…)

Answer

Drown picture Drown · Nov 7, 2015

You can use encode for that.

$data = (string) Image::make('public/bar.png')->encode('data-url');