Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.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 在GD IMG_FILTER_着色后将背景应用于PNG透明图像_Php_Png_Gd - Fatal编程技术网

Php 在GD IMG_FILTER_着色后将背景应用于PNG透明图像

Php 在GD IMG_FILTER_着色后将背景应用于PNG透明图像,php,png,gd,Php,Png,Gd,我有一个透明的png图像(它是单色的),我应用了彩色php GD过滤器。所以现在它是彩色的,但我很难用白色背景来消除透明度 list($r,$g,$b) = array_map('hexdec',str_split($ColourPrimary,2)); $r = $r - 52; $g = $g - 52; $b = $b - 52; imagesavealpha($im, true); imagefilter($im, IMG_FILTER_

我有一个透明的png图像(它是单色的),我应用了彩色php GD过滤器。所以现在它是彩色的,但我很难用白色背景来消除透明度

    list($r,$g,$b) = array_map('hexdec',str_split($ColourPrimary,2));
    $r = $r - 52;
    $g = $g - 52;
    $b = $b - 52;

    imagesavealpha($im, true);
    imagefilter($im, IMG_FILTER_COLORIZE, $r, $g, $b);

    $bw  = imagesx($im);
    $bh = imagesy($im);
    $background = imagecreatetruecolor($bw,$bh);
    $bkwhite = imagecolorallocate($background, 255, 255, 255);
    imagefill($background,0,0,$bkwhite);
    imagecopy($background, $im, 0, 0, 0, 0, $bw, $bh);

睡了一个好觉后,我意识到我是在倒退。我首先应用了背景,然后在顶部复制了图像

    list($r,$g,$b) = array_map('hexdec',str_split($ColourPrimary,2));
    $r = $r - 52;
    $g = $g - 52;
    $b = $b - 52;

    $imfore = imagecreatefrompng(FILELOCATION);
    imagesavealpha($imfore, true);
    imagefilter($imfore, IMG_FILTER_COLORIZE, $r, $g, $b);
    $bw  = imagesx($imfore);
    $bh = imagesy($imfore);

    $im = imagecreatetruecolor($bw,$bh);
    $bkwhite = imagecolorallocate($im, 255, 255, 255);
    imagefill($im,0,0,$bkwhite);
    imagecopy($im, $imfore, 0, 0, 0, 0,$bw,$bh);