new function to display text as images
[phpfspot.git] / phpfspot.class.php
1 <?php
2
3 require_once "phpfspot_cfg.php";
4 require_once "phpfspot_db.php";
5 require_once "phpfspot_tmpl.php";
6
7 class PHPFSPOT {
8
9    var $cfg;
10    var $db;
11    var $cfg_db;
12    var $tmpl;
13    var $tags;
14    var $avail_tags;
15    var $current_tags;
16
17    public function __construct()
18    {
19       $this->cfg = new PHPFSPOT_CFG;
20
21       $this->db = new PHPFSPOT_DB(&$this, $this->cfg->fspot_db);
22
23       $this->cfg_db = new PHPFSPOT_DB(&$this, $this->cfg->phpfspot_db);
24       $this->check_config_table();
25
26       $this->tmpl = new PHPFSPOT_TMPL($this);
27
28       $this->get_tags();
29
30       session_start();
31
32       if(!isset($_SESSION['tag_condition']))
33          $_SESSION['tag_condition'] = 'or';
34
35       if(!isset($_SESSION['searchfor']))
36          $_SESSION['searchfor'] = '';
37
38    } // __construct()
39
40    public function __destruct()
41    {
42
43    } // __destruct()
44
45    public function show()
46    {
47       $this->tmpl->assign('searchfor', $_SESSION['searchfor']);
48       $this->tmpl->assign('page_title', $this->cfg->page_title);
49       $this->tmpl->assign('current_condition', $_SESSION['tag_condition']);
50       $this->tmpl->show("index.tpl");
51
52    } // show()
53
54    private function get_tags()
55    {
56       $this->avail_tags = Array();
57       $count = 0;
58    
59       $result = $this->db->db_query("
60          SELECT id,name
61          FROM tags
62          ORDER BY sort_priority ASC
63       ");
64       
65       while($row = $this->db->db_fetch_object($result)) {
66
67          $tag_id = $row['id'];
68          $tag_name = $row['name'];
69
70          /* check if config requests to ignore this tag */
71          if(in_array($row['name'], $this->cfg->hide_tags))
72             continue;
73
74          $this->tags[$tag_id] = $tag_name; 
75          $this->avail_tags[$count] = $tag_id;
76
77          $count++;
78
79       }
80
81    } // get_tags()
82
83    public function get_photo_details($idx)
84    {
85       $result = $this->db->db_query("
86          SELECT *
87          FROM photos
88          WHERE id='". $idx ."'
89       ");
90       
91       return $this->db->db_fetch_object($result);
92
93    } // get_photo_details
94
95    public function translate_path($path, $width = 0)
96    {  
97       return str_replace($this->cfg->path_replace_from, $this->cfg->path_replace_to, $path);
98
99    } // translate_path
100
101    public function showPhoto($photo)
102    {
103       $all_photos = $this->getPhotoSelection();
104
105       foreach($all_photos as $all_photo) {
106          
107          if($get_next) {
108             $next_img = $all_photo;
109             break;
110          }
111
112          if($all_photo == $photo) {
113             $get_next = 1;
114          }
115          else {
116             $previous_img = $all_photo;
117          }
118       }
119
120       $details = $this->get_photo_details($photo);
121       $orig_path = $this->translate_path($details['directory_path']) ."/". $details['name'];
122       $thumb_path = $this->cfg->base_path ."/thumbs/". $this->cfg->photo_width ."_". $this->getMD5($photo);
123
124       if(!file_exists($orig_path)) {
125          print "Photo ". $orig_path ." does not exist!<br />\n";
126       }
127
128       if(!is_readable($orig_path)) {
129          print "Photo ". $orig_path ." is not readable for user ". get_current_user() ."<br />\n";
130       }
131
132       /* If the thumbnail doesn't exist yet, try to create it */
133       if(!file_exists($thumb_path)) {
134          $this->gen_thumb($photo, 0, 1);
135       }
136
137       $meta = $this->get_meta_informations($orig_path);
138
139       if(file_exists($thumb_path)) {
140
141          $info = getimagesize($thumb_path);
142
143          $this->tmpl->assign('description', $details['description']);
144          $this->tmpl->assign('image_name', $details['name']);
145
146          $this->tmpl->assign('width', $info[0]);
147          $this->tmpl->assign('height', $info[1]);
148          $this->tmpl->assign('ExifMadeOn', strftime("%a %x %X", $meta['FileDateTime']));
149          $this->tmpl->assign('ExifMadeWith', $meta['Make'] ." ". $meta['Model']);
150          $this->tmpl->assign('ExifOrigResolution', $meta['ExifImageWidth'] ."x". $meta['ExifImageLength']);
151          $this->tmpl->assign('ExifFileSize', round($meta['FileSize']/1024, 1));
152     
153          $this->tmpl->assign('image_url', 'phpfspot_img.php?idx='. $photo ."&amp;width=". $this->cfg->photo_width);
154          $this->tmpl->assign('image_url_full', 'phpfspot_img.php?idx='. $photo);
155
156          $this->tmpl->assign('tags', $this->get_photo_tags($photo));
157       }
158       else {
159          print "Can't open file ". $thumb_path ."\n";
160       }
161
162       if($previous_img) {
163          $this->tmpl->assign('previous_url', "javascript:showImage(". $previous_img .");");
164       }
165
166       if($next_img) {
167          $this->tmpl->assign('next_url', "javascript:showImage(". $next_img .");");
168       }
169
170       $this->tmpl->show("single_photo.tpl");
171
172    } // showPhoto()
173
174    public function getAvailableTags()
175    {
176       $result = $this->db->db_query("
177          SELECT tag_id as id, count(tag_id) as quantity
178          FROM photo_tags
179          INNER JOIN tags t
180             ON t.id = tag_id
181          GROUP BY tag_id
182          ORDER BY t.name ASC
183       ");
184
185       $tags = Array();
186
187       while($row = $this->db->db_fetch_object($result)) {
188          $tags[$row['id']] = $row['quantity'];
189       }
190
191       // change these font sizes if you will
192       $max_size = 125; // max font size in %
193       $min_size = 75; // min font size in %
194
195       // get the largest and smallest array values
196       $max_qty = max(array_values($tags));
197       $min_qty = min(array_values($tags));
198
199       // find the range of values
200       $spread = $max_qty - $min_qty;
201       if (0 == $spread) { // we don't want to divide by zero
202          $spread = 1;
203       }
204
205       // determine the font-size increment
206       // this is the increase per tag quantity (times used)
207       $step = ($max_size - $min_size)/($spread);
208
209       // loop through our tag array
210       foreach ($tags as $key => $value) {
211
212          if(isset($_SESSION['selected_tags']) && in_array($key, $_SESSION['selected_tags']))
213             continue;
214
215           // calculate CSS font-size
216           // find the $value in excess of $min_qty
217           // multiply by the font-size increment ($size)
218           // and add the $min_size set above
219          $size = $min_size + (($value - $min_qty) * $step);
220           // uncomment if you want sizes in whole %:
221          $size = ceil($size);
222
223          print "<a href=\"javascript:Tags('add', ". $key .");\" class=\"tag\" style=\"font-size: ". $size ."%;\">". $this->tags[$key] ."</a>, ";
224
225       }
226
227    } // getAvailableTags()
228
229    public function getSelectedTags()
230    {
231       foreach($this->avail_tags as $tag)
232       {
233          // return all selected tags
234          if(isset($_SESSION['selected_tags']) && in_array($tag, $_SESSION['selected_tags'])) {
235             print "<a href=\"javascript:Tags('del', ". $tag .");\" class=\"tag\">". $this->tags[$tag] ."</a>&nbsp;";
236          }
237
238       }
239
240    } // getSelectedTags()
241
242    public function addTag($tag)
243    {
244       if(!isset($_SESSION['selected_tags']))
245          $_SESSION['selected_tags'] = Array();
246
247       if(!in_array($tag, $_SESSION['selected_tags']))
248          array_push($_SESSION['selected_tags'], $tag);
249    
250    } // addTag()
251
252    public function delTag($tag)
253    {
254       if(isset($_SESSION['selected_tags'])) {
255          $key = array_search($tag, $_SESSION['selected_tags']);
256          unset($_SESSION['selected_tags'][$key]);
257          sort($_SESSION['selected_tags']);
258       }
259
260    } // delTag()
261
262    public function resetTags()
263    {
264       unset($_SESSION['selected_tags']);
265
266    } // resetTags()
267
268    public function getPhotoSelection()
269    {  
270       $tagged_photos = Array();
271
272       /* return a search result */
273       if(isset($_SESSION['searchfor']) && $_SESSION['searchfor'] != '') {
274          $result = $this->db->db_query("
275             SELECT DISTINCT photo_id
276                FROM photo_tags pt
277             INNER JOIN photos p
278                ON p.id=pt.photo_id
279             INNER JOIN tags t
280                ON pt.tag_id=t.id
281             WHERE t.name LIKE '%". $_SESSION['searchfor'] ."%'
282                ORDER BY p.time ASC
283          ");
284          while($row = $this->db->db_fetch_object($result)) {
285             array_push($tagged_photos, $row['photo_id']);
286          }
287          return $tagged_photos;
288       }
289
290       /* return according the selected tags */
291       if(isset($_SESSION['selected_tags']) && !empty($_SESSION['selected_tags'])) {
292          $selected = "";
293          foreach($_SESSION['selected_tags'] as $tag)
294             $selected.= $tag .",";
295          $selected = substr($selected, 0, strlen($selected)-1);
296
297          if($_SESSION['tag_condition'] == 'or') {
298             $result = $this->db->db_query("
299                SELECT DISTINCT photo_id
300                   FROM photo_tags pt
301                INNER JOIN photos p
302                   ON p.id=pt.photo_id
303                WHERE pt.tag_id IN (". $selected .")
304                ORDER BY p.time ASC
305             ");
306          }
307          elseif($_SESSION['tag_condition'] == 'and') {
308
309             /* Join together a table looking like
310
311                pt1.photo_id pt1.tag_id pt2.photo_id pt2.tag_id ...
312
313                so the query can quickly return all images matching the
314                selected tags in an AND condition
315
316             */
317
318             $query_str = "
319                SELECT DISTINCT pt1.photo_id
320                   FROM photo_tags pt1
321             ";
322
323             for($i = 0; $i < count($_SESSION['selected_tags']); $i++) {
324                $query_str.= "
325                   INNER JOIN photo_tags pt". ($i+2) ."
326                      ON pt1.photo_id=pt". ($i+2) .".photo_id
327                ";
328             }
329             $query_str.= "WHERE pt1.tag_id=". $_SESSION['selected_tags'][0];
330             for($i = 1; $i < count($_SESSION['selected_tags']); $i++) {
331                $query_str.= "
332                   AND pt". ($i+1) .".tag_id=". $_SESSION['selected_tags'][$i] ."
333                "; 
334             }
335             $result = $this->db->db_query($query_str);
336          }
337
338          while($row = $this->db->db_fetch_object($result)) {
339             array_push($tagged_photos, $row['photo_id']);
340          }
341          return $tagged_photos;
342       }
343
344       /* return all available photos */
345       $result = $this->db->db_query("
346          SELECT DISTINCT photo_id
347             FROM photo_tags pt
348          INNER JOIN photos p
349             ON p.id=pt.photo_id
350          ORDER BY p.time ASC
351       ");
352       while($row = $this->db->db_fetch_object($result)) {
353          array_push($tagged_photos, $row['photo_id']);
354       }
355       return $tagged_photos;
356
357    } // getPhotoSelection()
358
359    public function showPhotoIndex()
360    {
361       $photos = $this->getPhotoSelection();
362
363       $count = count($photos);
364
365       if(!$_SESSION['begin_with'] || $_SESSION['begin_with'] == 0)
366          $begin_with = 0;
367       else
368          $begin_with = $_SESSION['begin_with'];
369
370       if($this->cfg->rows_per_page == 0)
371          $end_with = $count;
372       else
373          $end_with = $begin_with + ($this->cfg->rows_per_page * $this->cfg->thumbs_per_row);
374
375    
376       $rows = 0;
377       $cols = 0;
378       $images[$rows] = Array();
379       $img_height[$rows] = Array();
380       $img_width[$rows] = Array();
381
382       for($i = $begin_with; $i < $end_with; $i++) {
383
384          $images[$rows][$cols] = $photos[$i];
385
386          $thumb_path = $this->cfg->base_path ."/thumbs/". $this->cfg->thumb_width ."_". $this->getMD5($photos[$i]);
387
388          if(file_exists($thumb_path)) {
389             $info = getimagesize($thumb_path); 
390             $img_width[$rows][$cols] = $info[0];
391             $img_height[$rows][$cols] = $info[1];
392          }
393
394          if($cols == $this->cfg->thumbs_per_row-1) {
395             $cols = 0;
396             $rows++;
397             $images[$rows] = Array();
398             $img_width[$rows] = Array();
399             $img_height[$rows] = Array();
400          }
401          else {
402             $cols++;
403          }
404       } 
405
406       // +1 for for smarty's selection iteration
407       $rows++;
408
409       if(isset($_SESSION['searchfor']) && $_SESSION['searchfor'] != '')
410          $this->tmpl->assign('searchfor', $_SESSION['searchfor']);
411
412       if($this->cfg->rows_per_page != 0) {
413          $previous_start = $begin_with - ($this->cfg->rows_per_page * $this->cfg->thumbs_per_row);
414          $next_start = $begin_with + ($this->cfg->rows_per_page * $this->cfg->thumbs_per_row);
415
416          if($begin_with != 0) 
417             $this->tmpl->assign("previous_url", "javascript:showPhotoIndex(". $previous_start .");"); 
418          if($end_with < $count)
419             $this->tmpl->assign("next_url", "javascript:showPhotoIndex(". $next_start .");"); 
420       }
421    
422       $this->tmpl->assign('count', $count);
423       $this->tmpl->assign('width', $this->cfg->thumb_width);
424       $this->tmpl->assign('images', $images);
425       $this->tmpl->assign('img_width', $img_width);
426       $this->tmpl->assign('img_height', $img_height);
427       $this->tmpl->assign('rows', $rows);
428       $this->tmpl->assign('columns', $this->cfg->thumbs_per_row);
429       $this->tmpl->show("photo_index.tpl");
430
431
432    } // showPhotoIndex()
433
434    public function showBubbleDetails($photo, $direction)
435    {
436       if($direction == "up")
437          $direction = "bubbleimg_up";
438       else
439          $direction = "bubbleimg_down";
440
441       $details = $this->get_photo_details($photo);
442       $orig_path = $this->translate_path($details['directory_path'])  ."/". $details['name'];
443
444       $image_url = "phpfspot_img.php?idx=". $photo ."&amp;width=". $this->cfg->bubble_width;
445
446       $filesize = filesize($orig_path);
447       $filesize = rand($filesize/1024, 2);
448
449       if(!file_exists($orig_path)) {
450          print "Photo ". $orig_path ." does not exist!<br />\n";
451          return;
452       }
453       
454       if(!is_readable($orig_path)) {
455          print "Photo ". $orig_path ." is not readable for user ". get_current_user() ."<br />\n";
456          return;
457       }
458
459       $img = getimagesize($orig_path);
460
461       $this->tmpl->assign('file_size', $filesize);
462       $this->tmpl->assign('width', $img[0]);
463       $this->tmpl->assign('height', $img[1]);
464       $this->tmpl->assign('file_name', $details['name']);
465       $this->tmpl->assign('image_id', $direction);
466       $this->tmpl->assign('image_url', $image_url);
467       $this->tmpl->show("bubble_details.tpl");
468
469    } // showBubbleDetails()
470
471    public function showCredits()
472    {
473       $this->tmpl->assign('version', $this->cfg->version);
474       $this->tmpl->assign('product', $this->cfg->product);
475       $this->tmpl->show("credits.tpl");
476
477    } // showCredits()
478
479    public function create_thumbnail($orig_image, $thumb_image, $width)
480    {  
481       if(!file_exists($orig_image))
482          return false;
483
484       $meta = $this->get_meta_informations($orig_image);
485
486       $rotate = 0;
487       $flip = false;
488
489       switch($meta['Orientation']) {
490
491          case 1:
492             $rotate = 0; $flip = false; break;
493          case 2:
494             $rotate = 0; $flip = true; break;
495          case 3:
496             $rotate = 180; $flip = false; break;
497          case 4:
498             $rotate = 180; $flip = true; break;
499          case 5:
500             $rotate = 90; $flip = true; break;
501          case 6:
502             $rotate = 90; $flip = false; break;
503          case 7:
504             $rotate = 270; $flip = true; break;
505          case 8:
506             $rotate = 270; $flip = false; break;
507       }
508
509       $src_img = @imagecreatefromjpeg($orig_image);
510
511       if(!$src_img) {
512          print "Can't load image from ". $orig_image ."\n";
513          return false;
514       }
515
516       /* grabs the height and width */
517       $new_w = imagesx($src_img);
518       $new_h = imagesy($src_img);
519
520       // If requested width is more then the actual image width,
521       // do not generate a thumbnail
522
523       if($width >= $new_w) {
524          imagedestroy($src_img);
525          return true;
526       }
527
528       /* calculates aspect ratio */
529       $aspect_ratio = $new_h / $new_w;
530
531       /* sets new size */
532       $new_w = $width;
533       $new_h = abs($new_w * $aspect_ratio);
534
535       /* creates new image of that size */
536       $dst_img = imagecreatetruecolor($new_w, $new_h);
537
538       imagefill($dst_img, 0, 0, ImageColorAllocate($dst_img, 255, 255, 255));
539
540       /* copies resized portion of original image into new image */
541       imagecopyresampled($dst_img,$src_img,0,0,0,0,$new_w,$new_h,imagesx($src_img),imagesy($src_img));
542
543       /* needs the image to be flipped horizontal? */
544       if($flip) {
545          print "(FLIP)";
546          $image = $dst_img;
547          for($x = 0; $x < $new_w; $x++) {
548             imagecopy($dst_img, $image, $x, 0, $w - $x - 1, 0, 1, $h);
549          }
550       }
551
552       if($rotate) {
553          print "(ROTATE)";
554          $dst_img = $this->rotateImage($dst_img, $rotate);
555       }
556
557       /* write down new generated file */
558       $result = imagejpeg($dst_img, $thumb_image, 75);
559
560       /* free your mind */
561       imagedestroy($dst_img);
562       imagedestroy($src_img);
563
564       if($result === false) {
565          print "Can't write thumbnail ". $thumb_image ."\n";
566          return false;
567       }
568
569       return true;
570
571    } // create_thumbnail()
572
573    public function get_meta_informations($file)
574    {
575       return exif_read_data($file);
576
577    } // get_meta_informations()
578
579    public function check_config_table()
580    {
581       // if the config table doesn't exist yet, create it
582       if(!$this->cfg_db->db_check_table_exists("images")) {
583          $this->cfg_db->db_exec("
584             CREATE TABLE images (
585                img_idx int primary key,
586                img_md5 varchar(32)
587             )
588             ");
589       }
590
591    } // check_config_table
592
593    /**
594     * Generates a thumbnail from photo idx
595     *
596     * This function will generate JPEG thumbnails from provided F-Spot photo
597     * indizes.
598     *
599     * 1. Check if all thumbnail generations (width) are already in place and
600     *    readable
601     * 2. Check if the md5sum of the original file has changed
602     * 3. Generate the thumbnails if needed
603     */
604    public function gen_thumb($idx = 0, $fromcmd = 0, $force = 0)
605    {
606       $resolutions = Array(
607          $this->cfg->thumb_width,
608          $this->cfg->bubble_width,
609          $this->cfg->photo_width,
610       );
611
612       $details = $this->get_photo_details($idx);
613       $full_path = $this->translate_path($details['directory_path'])  ."/". $details['name'];
614       $file_md5 = md5_file($full_path);
615
616       if($fromcmd) print "Image [". $idx ."] ". $details['name'] ." Thumbnails:";
617
618       $error = 0;
619
620       foreach($resolutions as $resolution) {
621
622          $thumb_path = $this->cfg->base_path ."/thumbs/". $resolution ."_". $file_md5;
623
624          /* if the thumbnail file doesn't exist, create it */
625          if(!file_exists($thumb_path)) {
626
627             if($fromcmd) print " ". $resolution ."px";
628             if(!$this->create_thumbnail($full_path, $thumb_path, $resolution))
629                $error = 1;
630
631          }
632
633          /* if the file hasn't changed there is no need to regen the thumb */
634          elseif($file_md5 != $this->getMD5($idx) || $force) {
635
636             if($fromcmd) print " ". $resolution ."px";
637             if(!$this->create_thumbnail($full_path, $thumb_path, $resolution))
638                $error = 1;
639
640          }
641       }
642
643       /* set the new/changed MD5 sum for the current photo */
644       if(!$error)
645          $this->setMD5($idx, $file_md5);
646
647       if($fromcmd) print "\n";
648
649    } // gen_thumb()
650
651    public function getMD5($idx)
652    {
653       $result = $this->cfg_db->db_query("
654          SELECT img_md5 
655          FROM images
656          WHERE img_idx='". $idx ."'
657       ");
658
659       if(!$result)
660          return 0;
661
662       $img = $this->cfg_db->db_fetch_object($result);
663       return $img['img_md5'];
664       
665    } // getMD5()
666
667    private function setMD5($idx, $md5)
668    {
669       $result = $this->cfg_db->db_exec("
670          REPLACE INTO images (img_idx, img_md5)
671          VALUES ('". $idx ."', '". $md5 ."')
672       ");
673
674    } // setMD5()
675
676    public function setTagCondition($mode)
677    {
678       $_SESSION['tag_condition'] = $mode;
679
680    } // setTagCondition()
681
682    public function startSearch($searchfor)
683    {
684       $_SESSION['searchfor'] = $searchfor;
685
686    } // startSearch()
687
688    private function rotateImage($img, $degrees)
689    {
690       if(function_exists("imagerotate"))
691          $img = imagerotate($img, $degrees, 0);
692       else
693       {
694          function imagerotate($src_img, $angle)
695          {
696             $src_x = imagesx($src_img);
697             $src_y = imagesy($src_img);
698             if ($angle == 180) {
699                $dest_x = $src_x;
700                $dest_y = $src_y;
701             }
702             elseif ($src_x <= $src_y) {
703                $dest_x = $src_y;
704                $dest_y = $src_x;
705             }
706             elseif ($src_x >= $src_y) {
707                $dest_x = $src_y;
708                $dest_y = $src_x;
709             }
710                
711             $rotate=imagecreatetruecolor($dest_x,$dest_y);
712             imagealphablending($rotate, false);
713                
714             switch ($angle) {
715             
716                case 90:
717                   for ($y = 0; $y < ($src_y); $y++) {
718                      for ($x = 0; $x < ($src_x); $x++) {
719                         $color = imagecolorat($src_img, $x, $y);
720                         imagesetpixel($rotate, $dest_x - $y - 1, $x, $color);
721                      }
722                   }
723                   break;
724
725                case 270:
726                   for ($y = 0; $y < ($src_y); $y++) {
727                      for ($x = 0; $x < ($src_x); $x++) {
728                         $color = imagecolorat($src_img, $x, $y);
729                         imagesetpixel($rotate, $y, $dest_y - $x - 1, $color);
730                      }
731                   }
732                   break;
733
734                case 180:
735                   for ($y = 0; $y < ($src_y); $y++) {
736                      for ($x = 0; $x < ($src_x); $x++) {
737                         $color = imagecolorat($src_img, $x, $y);
738                         imagesetpixel($rotate, $dest_x - $x - 1, $dest_y - $y - 1, $color);
739                      }
740                   }
741                   break;
742
743                default: $rotate = $src_img;
744             };
745
746             return $rotate;
747
748          }
749
750          $img = imagerotate($img, $degrees);
751
752       }
753
754       return $img;
755
756    } // rotateImage()
757
758    private function get_photo_tags($idx)
759    {
760       $result = $this->db->db_query("
761          SELECT t.id, t.name
762          FROM tags t
763          INNER JOIN photo_tags pt
764             ON t.id=pt.tag_id
765          WHERE pt.photo_id='". $idx ."'
766       ");
767
768       $tags = Array();
769
770       while($row = $this->db->db_fetch_object($result))
771          $tags[$row['id']] = $row['name'];
772
773       return $tags;
774
775    } // get_photo_tags()
776
777    function showTextImage($txt, $color=000000, $space=4, $font=4, $w=300)
778    {
779       if (strlen($color) != 6) 
780          $color = 000000;
781
782       $int = hexdec($color);
783       $h = imagefontheight($font);
784       $fw = imagefontwidth($font);
785       $txt = explode("\n", wordwrap($txt, ($w / $fw), "\n"));
786       $lines = count($txt);
787       $im = imagecreate($w, (($h * $lines) + ($lines * $space)));
788       $bg = imagecolorallocate($im, 255, 255, 255);
789       $color = imagecolorallocate($im, 0xFF & ($int >> 0x10), 0xFF & ($int >> 0x8), 0xFF & $int);
790       $y = 0;
791
792       foreach ($txt as $text) {
793          $x = (($w - ($fw * strlen($text))) / 2);
794          imagestring($im, $font, $x, $y, $text, $color);
795          $y += ($h + $space);
796       }
797
798       Header("Content-type: image/png");
799       ImagePng($im);
800
801    } // showTextImage()
802
803 }
804
805 ?>