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

Web Technologies-I



                   Notes         The width and height parameters specify the size of the pattern. If you are creating a pattern
                                 from an image, these are the dimensions of the image. The xstep and ystep parameters specify
                                 the horizontal and vertical tiling spacing (i.e., the distance between repetitions of the image). To
                                 tile the image without a gap between repetitions, set the xstep and ystep arguments to the same
                                 values as width and height. The final argument, painttype, can be either 1 or 2. 1 means that the
                                 pattern supplies its own color information. 2 means that the current fill and stroke colors are
                                 used instead. Patterns based on images only use a painttype of 1.
                                 Example creates a pattern from a small PHP logo image and uses it to fill a circle.

                                               Filling with a pattern

                                 <?php
                                 $p = pdf_new( );

                                 pdf_open_file($p);
                                 $im = pdf_open_jpeg($p, “php-tiny.jpg”);
                                 $pattern = pdf_begin_pattern($p,64,34,64,34,1);

                                 pdf_save($p);
                                 pdf_place_image($p, $im, 0,0,1);
                                 pdf_restore($p);
                                 pdf_end_pattern($p);

                                 pdf_close_image ($p,$im);
                                 pdf_begin_page($p,612,792);

                                 pdf_setcolor($p, “fill”, “pattern”, $pattern);
                                 pdf_setcolor($p, “stroke”, “pattern”, $pattern);
                                 pdf_setlinewidth($p, 30.0);
                                 pdf_circle($p,306,396,120);

                                 pdf_stroke($p);
                                 pdf_end_page($p);

                                 pdf_close($p);
                                 $buf = pdf_get_buffer($p);
                                 $len = strlen($buf);
                                 Header(“Content-Type:application/pdf”);

                                 Header(“Content-Length: $len”);
                                 Header(“Content-Disposition: inline; filename=pat.pdf”);
                                 echo $buf; pdf_delete($p);

                                 ?>
                                 The output of Example is shown in Figure 12.12.






        306                               LOVELY PROFESSIONAL UNIVERSITY
   307   308   309   310   311   312   313   314   315   316   317