Limon Monte
Limon Monte

Reputation: 54379

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

Upvotes: 12

Views: 20870

Answers (1)

Drown
Drown

Reputation: 5982

You can use encode for that.

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

Upvotes: 27

Related Questions