GD choosing what colors to display

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 ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-19-2004
RootShell
 
Posts: n/a
Default GD choosing what colors to display

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


Reply With Quote
  #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
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 08:47 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0