我正在使用Laravel 5.4开发API。我将以base64格式接收图片。如何在Laravel中将base64转换为图片?
我正在使用Laravel 5.4开发API。我将以base64格式接收图片。如何在Laravel中将base64转换为图片?
$image = $request->input('image'); // image base64 encoded
preg_match("/data:image\/(.*?);/",$image,$image_extension); // extract the image extension
$image = preg_replace('/data:image\/(.*?);base64,/','',$image); // remove the type part
$image = str_replace(' ', '+', $image);
$imageName = 'image_' . time() . '.' . $image_extension[1]; //generating unique file name;
Storage::disk('public')->put($imageName,base64_decode($image));
$image_extension
是什么?在这里没有定义。 - ahinkle1- 使用intervention image包
use Illuminate\Support\Facades\Storage;
use Intervention\Image\ImageManagerStatic;
use Illuminate\Support\Str;
$logo = ImageManagerStatic::make($request->logo)->encode('png');
$logo_name = Str::random(40) . '.png';
Storage::disk('s3')->put('products_seller/' . $logo_name, $logo);
use Illuminate\Support\Facades\Storage;
function createImageFromBase64(Request $request)
{
$file_data = $request->input('image_file');
$file_name = 'image_' . time() . '.png'; //generating unique file name;
if ($file_data != "") { // storing image in storage/app/public Folder
Storage::disk('public')->put($file_name, base64_decode($file_data));
}
}