Search code examples
laravelbase64intervention

Intervention Image - save to variable in base64 encoded format


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,…)


Solution

  • You can use encode for that.

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