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

Web Technologies-I



                   Notes         12.4.1 Images
                                 PDF supports many different embedded image formats: PNG, JPEG, GIF, TIFF, CCITT, and a
                                 raw image format that consists of a stream of the exact byte sequence of pixels. Not every feature
                                 of every format is supported, however.
                                 For PNG images, the alpha channel is lost (however, the later versions of pdflib and Acrobat
                                 do support transparency, which means that you can indicate a color index to be the transparent
                                 color, but you cannot have partial transparency). For JPEG, you only need to watch out for
                                 progressive JPEGs; they are not supported prior to Acrobat 4, so it is a good idea to stick to non
                                 progressive JPEGs. For GIF images, avoid interlacing.
                                 Adding an image to a PDF document is relatively simple. The first step is to call the appropriate
                                 open function for the type of image you are using. These functions all take the form pdf_open_
                                 format( ). For instance:
                                 $image = pdf_open_jpeg (pdf, filename);
                                 Once you have opened the image, use pdf_place_image( ) to indicate where in your document
                                 the image should be located. While you have an image open, you can place it multiple times
                                 throughout your document; your generated file will contain only one copy of the actual image
                                 data. When you are done placing your image, call the pdf_close_image( ) function:
                                 pdf_place_image(pdf, image, x, y, scale); pdf_close_image(pdf, image);

                                 You can get the dimensions  of an image via pdf_get_value( ) calls on the imagewidth and
                                 imageheight keywords.

                                                Placing and scaling images

                                 <?php

                                 $p = pdf_new( );
                                 pdf_open_file($p);
                                 pdf_set_info($p,”Creator”,”images.php”);

                                 pdf_set_info($p,”Author”,”ABC”);

                                 pdf_set_info($p,”Title”,”Images”);
                                 pdf_begin_page($p,612,792);
                                 $im = pdf_open_jpeg($p, “php-big.jpg”);

                                 pdf_place_image($p, $im, 200, 700, 1.0);

                                 pdf_place_image($p, $im, 200, 600, 0.75);
                                 pdf_place_image($p, $im, 200, 535, 0.50);
                                 pdf_place_image($p, $im, 200, 501, 0.25);

                                 pdf_place_image($p, $im, 200, 486, 0.10);

                                 $x = pdf_get_value($p, “imagewidth”, $im);
                                 $y = pdf_get_value($p, “imageheight”, $im);
                                 pdf_close_image ($p,$im);




        300                               LOVELY PROFESSIONAL UNIVERSITY
   301   302   303   304   305   306   307   308   309   310   311