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?
The first step is to create an image resource with functions such as imagecreatefrompng() . After that, you can use the function imagecolorat($image, $x, $y) to get the index of the color of a given pixel. The position of the pixel is determined by the second and third parameters in the function.
GD is an open source code library for the dynamic creation of images. GD is used for creating PNG, JPEG and GIF images and is commonly used to generate charts, graphics, thumbnails on the fly.
Zebra Image This is a compact (one-file only), lightweight, object-oriented image manipulation library written in and for PHP, that provides methods for performing several types of image manipulation operations.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With