steves has asked for the wisdom of the Perl Monks concerning the following question:
I know something like this must exist, but I can't find it ... I'd like to find a good starting point for building a simple Perl CGI that displays a clickable image map of colors, then just builds a simple page using a selected color as the background color. Any pointers?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: color selection image map
by vladb (Vicar) on May 22, 2002 at 21:40 UTC | |
Let me suggest you use this module CGI::Imagemap to build your HTMLized image maps via a Perl CGI script. Refer to the module documentation for more info (I found it very clear and descriptive). Hope this helps! ;) _____________________
| [reply] [d/l] |
|
Re: color selection image map
by mt2k (Hermit) on May 23, 2002 at 06:02 UTC | |
For the example, I have provided, as the list, the "web-safe" color palette. These are the colors that are supposedly displayed the same on all monitors/browsers. As a rule of thumb, only colors from this list should be used when designing web sites on the internet :)
| [reply] [d/l] |
by steves (Curate) on May 23, 2002 at 23:04 UTC | |
It turns out that ImageMagick makes this amazingly easy. They have a built in 'netscape' color cube image that just builds the grid. Here's the small chunk of code that does that:
You can also create the associated map, but I just used standard Perl CGI to generate a page using the image I created and field the image map params coming back. It looks at the coordinates and again uses ImageMagick to query the image's color at the location, convert that to hex and show the page again. Here's the CGI code ... a little fugly but I can clean it up later, right? 8-) This may not work as is -- there was another proprietary piece I can really put out for public consumption.
| [reply] [d/l] [select] |
by steves (Curate) on May 24, 2002 at 12:47 UTC | |
I also implemented a version that's entirely client side image maps and JavaScript, which actually fits the need a little better. No Perl in that one, but I thought I'd mention it as a final follow-up. I know all the evils of JavaScript, but in this case it makes sense ... | [reply] |
|
Re: color selection image map
by shotgunefx (Parson) on May 22, 2002 at 21:49 UTC | |
-Lee "To be civilized is to deny one's nature." | [reply] |
by shotgunefx (Parson) on May 22, 2002 at 22:10 UTC | |
You'll need to use GD or Image magik to generate the images which will be 255x255. Well that or generate a raw image file which I don't recommend. Use the x axis for green and y for red. What I mean is that point 0,0 should be (Red,Green) = (0,0) Point 255,255 will be (Red,Green) = (255,255). By using an image type input, you will be able to dicern what value the user clicked by using the x,y as indexes. You've now got the red and green values. You will need a text input field for Blue which you can think of as the z axis of the cube. The only downside is generating the images. You could generate them and store them instead for speed as uncompressed it's only about a meg total. When the user changes the blue axis, you just use that as an index to the right image (Or generate it dynamically). Then you just take the x,y of the click and the blue index and you have your color. The plus side of the complexity is that you can select any RGB value possible. I may get around coding this myself (It's been on my list for awhile) but right now I don't have the time to put it together. Good luck -Lee "To be civilized is to deny one's nature." | [reply] |