Can I swap colors in image using GD library in PHP?

前端 未结 8 1499
遇见更好的自我
遇见更好的自我 2020-12-03 08:18

I got the image like this (it\'s a graph):


(source: kitconet.com)

I want to change the colours, so the white is black, the graph line is li

8条回答
  •  盖世英雄少女心
    2020-12-03 08:30

    I had trouble making this solution work. The image cannot be a true color image. Convert it first with imagetruecolortopalette();

    $imgname = "test.gif";
    $im = imagecreatefromgif ($imgname);
    
    imagetruecolortopalette($im,false, 255);
    
    $index = imagecolorclosest ( $im,  255,255,255 ); // get White COlor
    imagecolorset($im,$index,92,92,92); // SET NEW COLOR
    
    $imgname = "result.gif";
    imagegif($im, $imgname ); // save image as gif
    imagedestroy($im);
    

提交回复
热议问题