Image Colour

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
stevil
Forum Newbie
Posts: 2
Joined: Sat Dec 20, 2008 3:32 pm

Image Colour

Post by stevil »

Hey all,

Basically the problem I have the moment is I'm working on a scrip someone sent me which generates a cube using poly imageFilledPolygon and imagePolygon for the edges. Now the thing is they want shading done on the different sides of the cube, but they're only passing in an individual colour pointer and I'm not sure how I can use this to convert it to a new colour which is darker. Is there a way to return the RGB or hex value off a colour thats been already allocated?
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: Image Colour

Post by andyhoneycutt »

After a bit of searching, I think I found what it is you're looking for, check out the imagecolorsforindex function. It returns the 0-255 value as well as the alpha for the color in an associative array.

-Andy
stevil
Forum Newbie
Posts: 2
Joined: Sat Dec 20, 2008 3:32 pm

Re: Image Colour

Post by stevil »

Hi, thanks heaps for the reply, it's exactly what I was looking for. In the process of looking things up I realised I could also do this:-

imageFilledPolygon($image,$vertices,count($poly),$fill + 0xF0F0F0);

This darkens the colour without having to convert it back to RGB like the function above does.
Post Reply