Fabric.js canvas.toDataURL() sent to PHP by Ajax

后端 未结 5 854
青春惊慌失措
青春惊慌失措 2021-02-06 14:44

I have a problem here when I need create a image with transparent background. I still don´t know if the problem is with fabricjs or with php. Everything works fine when I sent a

5条回答
  •  盖世英雄少女心
    2021-02-06 15:39

    I had the exact same problem and added this
    imageAlphaBlending($img, true);
    imageSaveAlpha($img, true);

    to rodrigopandini's code and it works perfect now.:)

     // createImage.php
    
    $data = base64_decode($_POST["str"]);
    
    $urlUploadImages = "../uploads/img/";
    $nameImage = "test.png";
    
          $img = imagecreatefromstring($data);
    
          imageAlphaBlending($img, true);
          imageSaveAlpha($img, true);
    
    if($img) {
        imagepng($img, $urlUploadImages.$nameImage, 0);
        imagedestroy($img);
    
        // [database code]
    
        echo "OK";
        }
         else {
              echo 'ERROR';
              }
    

提交回复
热议问题