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

后端 未结 5 857
青春惊慌失措
青春惊慌失措 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:36

    I don't know if this is exactly the problem you're experiencing, but some of the GD library's imagecreate* functions create images without the alpha channel.

    The workaround I've found is to create an image using imagecreatetruecolor and copy your transparent image onto it.

    Try a process like this:

    $img = imagecreatefromstring($data);
    $w = imagesx($img);
    $h = imagesy($img);
    $alpha_image = imagecreatetruecolor( $w, $h );
    imagecopyresampled( $alpha_image, $img, 0, 0, 0, 0, $w, $h, $w, $h );
    

    That should ensure that you end up with a "true color" image with the proper alpha channel.

提交回复
热议问题