View Single Post

  #2 (permalink)  
Old 10-19-2004
Shawn Wilson
 
Posts: n/a
Default Re: GD choosing what colors to display

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
Reply With Quote