Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/239.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/442.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php fabric js或imagick从图像中去除白色_Php_Javascript_Imagemagick_Transparency_Fabricjs - Fatal编程技术网

Php fabric js或imagick从图像中去除白色

Php fabric js或imagick从图像中去除白色,php,javascript,imagemagick,transparency,fabricjs,Php,Javascript,Imagemagick,Transparency,Fabricjs,我遇到了这种情况,我很难在谷歌上搜索和解释 我们公司在铝上打印照片,我们为客户提供两种选择 第一种选择是在铝上打印他们的照片,就像 他们把照片给了我们,所以如果照片是白色的 背景图片以白色背景打印。容易的 像那样 第二种选择是,我们可以不使用 白色通过使用颜色空间中的因子,我可以创建一个Fabric JS图像过滤器 为了得到我想要的结果,我做了很多尝试和错误。 因此,我没有(详细)描述这是如何工作的。 据我所知,我已经使用YUV因子来获得(RGB)颜色的亮度 (i=0;i

我遇到了这种情况,我很难在谷歌上搜索和解释

我们公司在铝上打印照片,我们为客户提供两种选择

  • 第一种选择是在铝上打印他们的照片,就像 他们把照片给了我们,所以如果照片是白色的 背景图片以白色背景打印。容易的 像那样

  • 第二种选择是,我们可以不使用
    白色通过使用颜色空间中的因子,我可以创建一个Fabric JS图像过滤器

    为了得到我想要的结果,我做了很多尝试和错误。 因此,我没有(详细)描述这是如何工作的。 据我所知,我已经使用YUV因子来获得(RGB)颜色的亮度

    (i=0;i{ 对于(j=0;j 不知何故,通过在最后一行中使用350,您可以改变透明度因子


    很抱歉,无法详细解释此结构过滤器的工作原理。

    因此,Fabric.js中有一个过滤器就是这样做的


    您可以在Fabric中创建自己的图像过滤器。例如,请查看灰度的来源,谢谢您的回复,我会查看它。我已经在摆弄您的Redify过滤器。在新的Fabric.js版本中,此方法名称更改为
    RemoveColor
    for (i = 0; i < iLen; i++) {
        for (j = 0; j < jLen; j++) {
          index = (i * 4) * jLen + (j * 4);
          var yuv = {};
          yuv.r = data[index] / 255 * 1 * 0.299;     
          yuv.g = data[index + 1] / 255 * 1 * 0.587; //we use the yuv formula constants
          yuv.b = data[index + 2] / 255 * 1 * 0.114; //to try to catch the Y (brightness)
          yuv.y = yuv.r + yuv.g + yuv.b;             //you can tweak this
          data[index + 3] = 350 - (yuv.y / 1 * 255); //by changing the first number after the "=" on this line!
        }
    }
    
    var filter = new fabric.Image.filters.RemoveWhite({
      threshold: 40,
      distance: 140
    });
    image.filters.push(filter);
    image.applyFilters(canvas.renderAll.bind(canvas));