How to save a PNG image server-side, from a base64 data string

后端 未结 15 2574
情话喂你
情话喂你 2020-11-22 03:18

I\'m using Nihilogic\'s \"Canvas2Image\" JavaScript tool to convert canvas drawings to PNG images. What I need now is to turn those base64 strings that this tool generates,

15条回答
  •  清歌不尽
    2020-11-22 03:43

    Well your solution above depends on the image being a jpeg file. For a general solution i used

    $img = $_POST['image'];
    $img = substr(explode(";",$img)[1], 7);
    file_put_contents('img.png', base64_decode($img));
    

提交回复
热议问题