Page 282 - Open Soource Technologies 304.indd
P. 282

Web Technologies-I



                   Notes
                                                   Figure 11.13: Image with Alpha Blending Enabled











                                              Develop a PHP program to show an orange circle over the gray ellipse.

                                 11.8.2 Identifying Colours
                                 To check the colour index for a specific pixel in an image, use ImageColorAt( ):

                                 $color = ImageColorAt(image, x, y);


                                 For images with an 8-bit colour palette, the function returns a colour index that you then pass
                                 to ImageColorsForIndex( ) to get the actual RGB values:
                                 $values = ImageColorsForIndex(image, index);



                                 The array returned by ImageColorsForIndex( ) has keys “red”, “green”, and “blue”. If you
                                 call ImageColorsForIndex( ) on a colour from a true colour image, the returned array has an
                                 extra key, “alpha”.
                                 11.8.3 True Colour Indexes

                                 The colour index returned by  ImageColorResolveAlpha( ) is really a 32-bit signed long,
                                 with the first three  bytes  holding the  red, green,  and blue  values, respectively. The next  bit
                                 indicates whether antialiasing is enabled for this colour, and the remaining seven bits hold the
                                 transparency value.


                                 $green = ImageColorResolveAlpha($im,0,0,255,127);



                                 This code sets $green to 2130771712, which in hex is 0x7F00FF00 and in binary is 0111111100
                                 0000001111111100000000.
                                 This is equivalent to the following ImageColorResolveAlpha( ) call:
                                 $green = 127<<24 | 0<<16 | 255<<8 | 0;



                                 You can also drop the two 0 entries in this example and just make it:
                                 $green = 127<<24 | 255<<8;



                                 To deconstruct this value, you can use something like this:
                                 $a = ($col & 0x7F000000) >> 24;

                                 $r = ($col & 0x00FF0000) >> 16;


        276                               LOVELY PROFESSIONAL UNIVERSITY
   277   278   279   280   281   282   283   284   285   286   287