PHP GD -> get color -> print color

Hello everyone!

I need a little help to get functions names from the GD library.
first i want to say i have a little knowledge with GD library like create image with words and etc.

So , what i’m trying to do is to take image and than
take the color of the first pixel on the top left than do some function work and than
set this pixel on the top left to another color.

now , i know how the algorithm should look like , i just don’t know what function i need to use to:
take specific pixel color from the image
set new color for pixel on specific place

i’ll be glad if you could help me with that ,
regards , Mor.

Getting function names from a library is as simple as looking at the manual page for [FPHP]GD[/FPHP]. Specifically, you’re looking for imagecreatefrom<type>, [FPHP]imagecolorat[/FPHP], and [FPHP]imagesetpixel[/FPHP]

I think you’ll need the imagecolorat() function to get the colour of the pixel.

The imagesetpixel() function is probably what your looking for to set a pixel to a certain colour.

wow thank you guys , it really really helped !
but i need to work with hex not with rgb , how can it work out?

hex = “#”.[FPHP]dechex/FPHP.[FPHP]dechex/FPHP.[FPHP]dechex/FPHP;

wow , this is my favorite community! thanks.

hey i got two more questions :
how can i save image that i made with gd?
and how can i open image that exist in the upload folder and put it into variable so i can take the size of the image and some other things…?
thanks , Mor.

imagecreatefrom<type> will put an image into a variable.
As far as saving them, write the result of your image generation function ([FPHP]imagepng[/FPHP], [FPHP]imagejpeg[/FPHP] etc) into a file, with something like [FPHP]file_put_contents[/FPHP].

thank you

i though i had problem , but it solve , sorry.

imagesetpixel’s color parameter is not a hex string, but a color object, as created by [FPHP]imagecolorallocate[/FPHP].