在GD IMG_FILTER_COLORIZE

时间:2017-03-05 15:56:46

标签: php png gd

我有透明的png图像(它是单色的),我应用了colourise 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);

1 个答案:

答案 0 :(得分:1)

经过一夜安眠后,我意识到自己正在倒退。我首先应用背景并将图像复制到顶部。

$(function(){

  $.ajax({

      dataType: "json",

      url: 'path/to/json/file.json',

      success: function(result){

         // you can process the JSON result first
         // and call other functions after this point

      }

      });

  });