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

Open Source Technologies



                   Notes               The fifth parameter is for the text to print, and the final parameter the colour of the text.
                                      This is the same colour that was allocated earlier using imagecolorallocate().
                                    •  Drawing a Line and Setting the Thickness of the Brush

                                       The imageline() function can be used to draw a line to the image. To set the thickness of
                                      the brush used to draw the line, you may want to call the imagesetthickness() function
                                      as I did in my example. The numeric parameter to imagesetthickness() is the thickness of
                                      the brush in pixels. If you don’t call imagesetthickness(), the line will be 1 pixel thick.

                                       The imageline() function is called with the start and end coordinates of the line, in x,y
                                      format. The line starts from 30,45 and ends on 165,45. That is, it will be a horizontal line 45
                                      pixels from the top, starting 30 pixels from the left edge and ending 165 pixels from that
                                      same edge. Since $line_colour was set to a shade of green earlier, the line will be green.

                                    •  How to Output the Image
                                       Since the output of example script is the image itself, send an “image/png” content type
                                      header to the browser telling it that what follows are the bytes of a PNG image. The
                                      function imagepng() is then called to generate the necessary image from $my_img image
                                      identifer. If you prefer to save your image, don’t call the header() function to output the
                                      header, and call imagepng() with the filename of the image for its second parameter, like
                                      the following:

                                       imagepng( $my_img, “my_new_image.png” );
                                       Your image does not have to be a PNG image. You can use imagegif() or imagejpeg() to
                                      create GIF and JPG images respectively. You should of course send the correct content
                                      type header for the type of image you are creating. For example, a jpeg image should
                                      have a content type of “image/jpeg” while a gif image “image/gif”. Note though that
                                      GIF support may or may not necessarily be compiled into the version of the GD library
                                      your web host is using, so if you’re not sure, use one of the other file formats.

                                    •  Freeing Resources
                                       On completion, the program releases the resources associated with the image by
                                      callingimagecolordeallocate() and imagedestroy().

                                                Colours are represented by three digits, known as the RGB value. The first
                                                digit denotes the red component, the second the green and the third blue.
                                                These colours are used for web pages as well as numerous other computer
                                                applications.
                                                The fonts have various sizes, ranging from 1 to 5, where 1 is the smallest font
                                                size and 5 the largest.

                                 12.2  Necessary Modifications to PHP

                                 Current versions of the PHP distribution include a bundled version of GD graphics library. The
                                 inclusion of this library eliminates the need to download and install several third-party libraries,
                                 but this library will need to be activated at installation time.




        200                               LOVELY PROFESSIONAL UNIVERSITY
   200   201   202   203   204   205   206   207   208   209   210