12

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

Limon Monte
  • 52,539
  • 45
  • 182
  • 213

1 Answers1

27

You can use encode for that.

$data = (string) Image::make('public/bar.png')->encode('data-url');
Drown
  • 5,852
  • 1
  • 30
  • 49