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

Unit 11: Graphics



            You can use the ImageTrueColorToPalette( ) function to convert a true colour image to one   Notes
            with a colour index (also known as a paletted image).




                        Develop a PHP program to show a white circle on a black background.
            11.8.1 Using the Alpha Channel

            In above Example, we turned off alpha blending before drawing our background and our ellipse.
            Alpha blending is a toggle that determines whether the alpha channel, if present, should be
            applied when drawing. If alpha blending is off, the old pixel is replaced with the new pixel.
            If an alpha channel exists for the new pixel, it is maintained, but all pixel information for the
            original pixel being overwritten is lost.
            Example illustrates alpha blending by drawing a gray rectangle with a 50% alpha channel over
            an orange ellipse.
                          A gray rectangle with a 50% alpha channel overlaid.

            <?php
            $im = ImageCreateTrueColor(150,150);

            $white = ImageColorAllocate($im,255,255,255);
            ImageAlphaBlending($im, false);
            ImageFilledRectangle($im,0,0,150,150,$white);

            $red = ImageColorResolveAlpha($im,255,50,0,63);
            ImageFilledEllipse($im,75,75,80,50,$red);
            $gray = ImageColorResolveAlpha($im,70,70,70,63);
            ImageAlphaBlending($im, false);

            ImageFilledRectangle($im,60,60,120,120,$gray);
            header(‘Content-Type: image/png’);

            ImagePNG($im);
            ?>
            Figure 11.12 shows the output of example (alpha blending is still turned off).


                           Figure 11.12: A Gray Rectangle over the Orange Ellipse








            If we change Example to enable alpha blending just before the call to Image-FilledRectangle(
            ), we get the image shown in Figure 11.13.








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