欢迎光临
我们一直在努力

对base64_encode格式的图片进行解码

对图片进行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());
         }
赞(0)
版权归原作者所有,如有侵权请告知。达维营-前端网 » 对base64_encode格式的图片进行解码

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址