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

前端 未结 5 953
借酒劲吻你
借酒劲吻你 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 18:59

    I generete a image with javascript/kendo and send this by ajax to the server.

    preg_replace('#^data:image/[^;]+;base64,#', '', $s['image']); 
    

    it does not work in this case. in my case this code works better:

    $contentType  = mime_content_type($s['image']);
    $img = preg_replace('#^data:image/(.*?);base64,#i', '$2', $s['image']);
    

提交回复
热议问题