Generate png-file with php from dataURI sent through ajax

前端 未结 2 1446
日久生厌
日久生厌 2021-01-14 21:33

I have an svg file that is generating a dataURI-png and that works great. And I want that dataURI to be saved as an image, therefore I try to send the dataURI through ajax t

2条回答
  •  时光说笑
    2021-01-14 22:20

    $dataUrl = $_REQUEST['datauri'];
    $id = $_REQUEST['id'];
    
    list($meta, $content) = explode(',', $dataUrl);
    
    $content = str_replace(".", "", $content); // some android browsers will return a data64 that may not be accurate without this without this.
    
    $content = base64_decode($content);
    $image = imagecreatefromstring($content);
    
    imagepng($image, './tmp-png/'.$id.'.png', 90); // Third parameter is optional. Just placed it incase you want to save storage space...
    

提交回复
热议问题