图片base64编码:
public function base64EncodeImage($image_file)
{
#$image_file文件地址,就对路径或者网络访问路径都可以
$base64_image = '';
$image_info = getimagesize($image_file);
$image_data = fread(fopen($image_file, 'r'), filesize($image_file));
$base64_image = 'data:' . $image_info['mime'] . ';base64,' . chunk_split(base64_encode($image_data));
return $base64_image;
}
图片base64解码并存储:
try {
$code_arr = substr($encodedstring, strpos($encodedstring, ",") + 1);
$size = Storage::disk('local_ftp_root')->put($full_path, base64_decode(chunk_split($code_arr)));
$url = Storage::disk('local_ftp_root')->url($full_path);
return $this->outPutJson($url);
} catch (\Exception $e) {
return $this->outPutJson('', 201, $e->getMessage());
}