我正在使用 Croppie 脚本在上传到我的服务器之前编辑图像。
https://foliotek.github.io/Croppie/
问题是 Croppie 以 base64 格式对裁剪后的图像进行编码。我创建了一个隐藏输入并附加了 base64 字符串。我需要知道如何获取字符串,以便我可以对其进行解码并将其与我的表单一起发布。
我尝试了很多方法,但我被卡住了。任何帮助将不胜感激
控制器
$post = new Post;
$post->post_category_id = $request->post_category_id;
$post->title = $request->title;
$post->body = $request->body;
$post->meta_description = $request->meta_description;
$post->slug = $request->slug;
$post->user_id = auth()->id();
$image = $request->input('featimage'); // 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)
$post->save();
}
翻阅古今
react native 怎么保存base64为图片文件
svg 有输出 base64 的 api 吗?
图片格式转换问题
laravel怎么把对象转换为数组