Generate png-file with php from dataURI sent through ajax

前端 未结 2 1444
日久生厌
日久生厌 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:21

    You can use canvas.toBlob(), send image to php as a Blob, use php://input to read Blob at php , see Beyond $_POST, $_GET and $_FILE: Working with Blob in JavaScript and PHP

    javascript

    if (!HTMLCanvasElement.prototype.toBlob) {
     Object.defineProperty(HTMLCanvasElement.prototype, "toBlob", {
      value: function (callback, type, quality) {
    
        var binStr = atob( this.toDataURL(type, quality).split(",")[1] ),
            len = binStr.length,
            arr = new Uint8Array(len);
    
        for (var i=0; i

    readBlobInput.php

    
    

提交回复
热议问题