我可以在 PHP 中使用 GD 库交换图像中的颜色吗?

2021-12-29 00:00:00 swap colors php gd imagefilter

我得到了这样的图像(它是一个图表):


(来源:

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 light blue, etc.. is it possible to achieve with GD and PHP?

解决方案

This will replace the white color with Gray

$imgname = "test.gif";
$im = imagecreatefromgif ($imgname);

$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);

相关文章