This is a discussion on GD choosing what colors to display within the PHP Language forums, part of the PHP Programming Forums category; Hello How can i use the GD Library to only show the White (or the hex value of white) pixels ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hello
How can i use the GD Library to only show the White (or the hex value of white) pixels of a image? Imagine i have a 8 color picture in PNG format. This is to use on a color puzzle that im trying to build... 1 - The user sees a completely BLACK image with the original size of the picture 2 - the user selects GREEN (from a color palete) 3 - the image updates and shows all BLACK/GREEN pixels (using something like "ShowImage.php?c=BG" or anything else) 4 - the user selects RED (from a color palete) 5 - the image updates and shows all BLACK/GREEN/RED pixels (using something like "ShowImage.php?c=BGR" or anything else) and so on... Is this possible using the GD Library? I can read the file from PNG and show it (using the gd library), i can even change the pallete of the image based on another file's pallete, but i wanted to dynamicaly change which colors to show on screen, based on user input. Any help on this appreciated, since im feeling a lit bit lost... Even the funtion that has to be used to achive this will be enough for getting me started. Thanks, RootShell |
|
|||
|
RootShell wrote:
> > How can i use the GD Library to only show the White (or the hex value of > white) pixels of a image? > > Imagine i have a 8 color picture in PNG format. > > This is to use on a color puzzle that im trying to build... > > 1 - The user sees a completely BLACK image with the original size of > the picture > > 2 - the user selects GREEN (from a color palete) > > 3 - the image updates and shows all BLACK/GREEN pixels (using > something like "ShowImage.php?c=BG" or anything else) > > 4 - the user selects RED (from a color palete) > > 5 - the image updates and shows all BLACK/GREEN/RED pixels (using > something like "ShowImage.php?c=BGR" or anything else) This isn't too difficult. You'll probably want to use imgcolorstotal, imagecolorat, imagecolorset and imagecolorsforindex. Loop through all the colors in the palette and set any color that's not one you want to display to a default color. Note: you imagecolorstotal() doesn't work for true color images. You may even be able to use some of those functions to determine what colors are in the image and offer them in a dynamically-generated server-side image map. That way you don't have to worry about your users clicking colors that aren't in the image. Just keep track of what colors are selected in a session variable. In other words, allocate a 25x25px block to each color. If the user clicks between 0,0 and 24,24 (corresponding to index color #1), then show that color. This may or may not apply to your situation. I don't know what the images are or how you get them. Shawn -- Shawn Wilson shawn@glassgiant.com http://www.glassgiant.com |