Forum Moderators: open
1. Would this kind of intense matrix cell structure be to much for some browsers to handle?
2. Does anyone know where I might be able to find information on the logic for the color combinations?
It sure would be cool to have anti-aliased rounded corners created dynamically like that, and without a single image file involved.
dmorison - That's a really nice offer, but I'm strictly a Perl user. Do you have any tips for me when setting up my version of this thing?
dmorison - That's a really nice offer, but I'm strictly a Perl user. Do you have any tips for me when setting up my version of this thing?
If Perl has an easy way to generate images on the fly then it should be straight forward enough to do the same thing.
The way I went about it was to first draw a smooth anti-aliased corner of black on white in each of the dimensions required using an art package, and then saved the images as a bitmap using only 5 colours.
I then studied the bitmaps and created static arrays for each of the dimensions required containing the numbers 0 through 4, where 0 represents the background colour; and 4 the foreground colour.
Here's the bitmap array for a 7x7 pixel corner:
$r[7][0] = array(2,4,4,4,4,4,4);
$r[7][1] = array(1,4,4,4,4,4,4);
$r[7][2] = array(0,4,4,4,4,4,4);
$r[7][3] = array(0,1,4,4,4,4,4);
$r[7][4] = array(0,0,1,4,4,4,4);
$r[7][5] = array(0,0,0,1,4,4,4);
$r[7][6] = array(0,0,0,0,0,1,2);
The inputs to the script are:
$fg (foreground colour)
$bg (background colour)
$cr (curve radius)
$or (orientation - "TL" for top-left, "TR" for top-right etc.)
Using PHP's image library, I then create a palette of the 5 colours needed to create the image - 0 being $bg (background), 4 being $fg (foreground); and 1,2 and 3 being the shades directly in between. There's probably a clever way to do it; but I just calculated the values at 1/4, 1/2 and 3/4 in between foreground and background for each of red green and blue.
Having setup the palette, it is then a case of setting the pixels. The script refers to the bitmap array of the appropriate radius; calling out of the array in the order required for the orientation of the corner ($or).
The PHP functions used to do the job in total are:
$image = imagecreate( $x, $y )
$color = imagecolorallocate( $image, $red, $green, $blue )
imagesetpixel( $image, $x, $y, $color )
and finally:
echo (imagepng( $image ))
to send the output to the browser.
It would be straight forward to create an implementation of this that uses a cache directory to save rebuilding the images every time.
That should be enough info for a Perl hacker to recreate the same thing. The time consuming bit was creating the bitmaps - they should be easy to convert from PHP into Perl so sticky me if you want the source.