laravel 干预图像 - 以 base64 编码格式保存到变量

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33585592/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 12:39:28  来源:igfitidea点击:

Intervention Image - save to variable in base64 encoded format

laravelbase64intervention

提问by Limon Monte

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

我将 Laravel 与图像处理包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.

save(),但它只保存到文件。

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

如何将修改后的干预图像导出到字符串变量?( data:image/jpeg;base64,…)

回答by Drown

You can use encodefor that.

您可以为此使用编码

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