Php 在GD IMG_FILTER_着色后将背景应用于PNG透明图像
我有一个透明的png图像(它是单色的),我应用了彩色php GD过滤器。所以现在它是彩色的,但我很难用白色背景来消除透明度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_
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);