How can I strip the data:image part from a base64 string of any image type in PHP

前端 未结 5 968
借酒劲吻你
借酒劲吻你 2021-01-04 18:29

I am currently doing the following to decode base64 images in PHP:

   $img = str_replace(\'data:image/jpeg;base64,\', \'\', $s[\'image\']);
   $img = str_rep         


        
5条回答
  •  一个人的身影
    2021-01-04 19:07

    Function file_get_contents remove header and use base64_decode function, so you get clear content image.

    Try this code:

    $img = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA0gA...';
    $imageContent = file_get_contents($img);
    

提交回复
热议问题