3 require_once "phpfspot_cfg.php";
4 require_once "phpfspot_db.php";
5 require_once "phpfspot_tmpl.php";
17 public function __construct()
19 /* Check necessary requirements */
20 if(!$this->checkRequirements()) {
24 $this->cfg = new PHPFSPOT_CFG;
26 $this->db = new PHPFSPOT_DB(&$this, $this->cfg->fspot_db);
27 $this->cfg_db = new PHPFSPOT_DB(&$this, $this->cfg->phpfspot_db);
28 $this->check_config_table();
30 $this->tmpl = new PHPFSPOT_TMPL($this);
36 if(!isset($_SESSION['tag_condition']))
37 $_SESSION['tag_condition'] = 'or';
39 if(!isset($_SESSION['searchfor']))
40 $_SESSION['searchfor'] = '';
42 // if begin_with is still set but rows_per_page is now 0, unset it
43 if(isset($_SESSION['begin_with']) && $this->cfg->rows_per_page == 0)
44 unset($_SESSION['begin_with']);
48 public function __destruct()
53 public function show()
55 $this->tmpl->assign('searchfor', $_SESSION['searchfor']);
56 $this->tmpl->assign('page_title', $this->cfg->page_title);
57 $this->tmpl->assign('current_condition', $_SESSION['tag_condition']);
59 switch($_GET['mode']) {
61 if(isset($_GET['tags'])) {
62 $_SESSION['selected_tags'] = split(',', $_GET['tags']);
67 $this->tmpl->assign('content_page', 'welcome.tpl');
68 $this->tmpl->show("index.tpl");
73 private function get_tags()
76 $this->avail_tags = Array();
79 $result = $this->db->db_query("
82 ORDER BY sort_priority ASC
85 while($row = $this->db->db_fetch_object($result)) {
88 $tag_name = $row['name'];
90 /* check if config requests to ignore this tag */
91 if(in_array($row['name'], $this->cfg->hide_tags))
94 $this->tags[$tag_id] = $tag_name;
95 $this->avail_tags[$count] = $tag_id;
103 public function get_photo_details($idx)
105 $result = $this->db->db_query("
108 WHERE id='". $idx ."'
111 return $this->db->db_fetch_object($result);
113 } // get_photo_details
115 public function getPhotoName($idx)
117 if($details = $this->get_photo_details($idx)) {
119 $name = $details['name'];
121 if(strlen($name) > 15) {
122 $name = substr($name, 0, 10) ."...". substr($name, -10);
131 public function translate_path($path, $width = 0)
133 return str_replace($this->cfg->path_replace_from, $this->cfg->path_replace_to, $path);
137 public function showPhoto($photo)
139 $all_photos = $this->getPhotoSelection();
140 $count = count($all_photos);
142 for($i = 0; $i < $count; $i++) {
145 $next_img = $all_photos[$i];
149 if($all_photos[$i] == $photo) {
153 $previous_img = $all_photos[$i];
156 if($photo == $all_photos[$i]) {
161 $details = $this->get_photo_details($photo);
162 $orig_path = $this->translate_path($details['directory_path']) ."/". $details['name'];
163 $thumb_path = $this->cfg->base_path ."/thumbs/". $this->cfg->photo_width ."_". $this->getMD5($photo);
165 if(!file_exists($orig_path)) {
166 $this->_warning("Photo ". $orig_path ." does not exist!<br />\n");
169 if(!is_readable($orig_path)) {
170 $this->_warning("Photo ". $orig_path ." is not readable for user ". get_current_user() ."<br />\n");
173 /* If the thumbnail doesn't exist yet, try to create it */
174 if(!file_exists($thumb_path)) {
175 $this->gen_thumb($photo, true);
178 $meta = $this->get_meta_informations($orig_path);
180 $meta_date = isset($meta['FileDateTime']) ? strftime("%a %x %X", $meta['FileDateTime']) : "n/a";
181 $meta_make = isset($meta['Make']) ? $meta['Make'] ." ". $meta['Model'] : "n/a";
182 $meta_res = isset($meta['ExifImageWidth']) ? $meta['ExifImageWidth'] ."x". $meta['ExifImageLength'] : "n/a";
183 $meta_size = isset($meta['FileSize']) ? round($meta['FileSize']/1024, 1) ."kbyte" : "n/a";
185 if(file_exists($thumb_path)) {
187 $info = getimagesize($thumb_path);
189 $this->tmpl->assign('description', $details['description']);
190 $this->tmpl->assign('image_name', $details['name']);
192 $this->tmpl->assign('width', $info[0]);
193 $this->tmpl->assign('height', $info[1]);
194 $this->tmpl->assign('ExifMadeOn', $meta_date);
195 $this->tmpl->assign('ExifMadeWith', $meta_make);
196 $this->tmpl->assign('ExifOrigResolution', $meta_res);
197 $this->tmpl->assign('ExifFileSize', $meta_size);
199 $this->tmpl->assign('image_url', 'phpfspot_img.php?idx='. $photo ."&width=". $this->cfg->photo_width);
200 $this->tmpl->assign('image_url_full', 'phpfspot_img.php?idx='. $photo);
202 $this->tmpl->assign('tags', $this->get_photo_tags($photo));
203 $this->tmpl->assign('current', $current);
206 $this->_warning("Can't open file ". $thumb_path ."\n");
210 $this->tmpl->assign('previous_url', "javascript:showImage(". $previous_img .");");
214 $this->tmpl->assign('next_url', "javascript:showImage(". $next_img .");");
217 $this->tmpl->show("single_photo.tpl");
221 public function getAvailableTags()
223 $result = $this->db->db_query("
224 SELECT tag_id as id, count(tag_id) as quantity
234 while($row = $this->db->db_fetch_object($result)) {
235 $tags[$row['id']] = $row['quantity'];
238 // change these font sizes if you will
239 $max_size = 125; // max font size in %
240 $min_size = 75; // min font size in %
242 // get the largest and smallest array values
243 $max_qty = max(array_values($tags));
244 $min_qty = min(array_values($tags));
246 // find the range of values
247 $spread = $max_qty - $min_qty;
248 if (0 == $spread) { // we don't want to divide by zero
252 // determine the font-size increment
253 // this is the increase per tag quantity (times used)
254 $step = ($max_size - $min_size)/($spread);
256 // loop through our tag array
257 foreach ($tags as $key => $value) {
259 if(isset($_SESSION['selected_tags']) && in_array($key, $_SESSION['selected_tags']))
262 // calculate CSS font-size
263 // find the $value in excess of $min_qty
264 // multiply by the font-size increment ($size)
265 // and add the $min_size set above
266 $size = $min_size + (($value - $min_qty) * $step);
267 // uncomment if you want sizes in whole %:
270 print "<a href=\"javascript:Tags('add', ". $key .");\" class=\"tag\" style=\"font-size: ". $size ."%;\">". $this->tags[$key] ."</a>, ";
274 } // getAvailableTags()
276 public function getSelectedTags()
278 foreach($this->avail_tags as $tag)
280 // return all selected tags
281 if(isset($_SESSION['selected_tags']) && in_array($tag, $_SESSION['selected_tags'])) {
282 print "<a href=\"javascript:Tags('del', ". $tag .");\" class=\"tag\">". $this->tags[$tag] ."</a> ";
287 } // getSelectedTags()
289 public function addTag($tag)
291 if(!isset($_SESSION['selected_tags']))
292 $_SESSION['selected_tags'] = Array();
294 if(!in_array($tag, $_SESSION['selected_tags']))
295 array_push($_SESSION['selected_tags'], $tag);
299 public function delTag($tag)
301 if(isset($_SESSION['selected_tags'])) {
302 $key = array_search($tag, $_SESSION['selected_tags']);
303 unset($_SESSION['selected_tags'][$key]);
304 sort($_SESSION['selected_tags']);
309 public function resetTags()
311 unset($_SESSION['selected_tags']);
315 public function resetTagSearch()
317 unset($_SESSION['searchfor']);
319 } // resetTagSearch()
321 public function getPhotoSelection()
323 $tagged_photos = Array();
325 /* return a search result */
326 if(isset($_SESSION['searchfor']) && $_SESSION['searchfor'] != '') {
327 $result = $this->db->db_query("
328 SELECT DISTINCT photo_id
334 WHERE t.name LIKE '%". $_SESSION['searchfor'] ."%'
337 while($row = $this->db->db_fetch_object($result)) {
338 array_push($tagged_photos, $row['photo_id']);
340 return $tagged_photos;
343 /* return according the selected tags */
344 if(isset($_SESSION['selected_tags']) && !empty($_SESSION['selected_tags'])) {
346 foreach($_SESSION['selected_tags'] as $tag)
347 $selected.= $tag .",";
348 $selected = substr($selected, 0, strlen($selected)-1);
350 if($_SESSION['tag_condition'] == 'or') {
351 $result = $this->db->db_query("
352 SELECT DISTINCT photo_id
356 WHERE pt.tag_id IN (". $selected .")
360 elseif($_SESSION['tag_condition'] == 'and') {
362 /* Join together a table looking like
364 pt1.photo_id pt1.tag_id pt2.photo_id pt2.tag_id ...
366 so the query can quickly return all images matching the
367 selected tags in an AND condition
372 SELECT DISTINCT pt1.photo_id
376 for($i = 0; $i < count($_SESSION['selected_tags']); $i++) {
378 INNER JOIN photo_tags pt". ($i+2) ."
379 ON pt1.photo_id=pt". ($i+2) .".photo_id
382 $query_str.= "WHERE pt1.tag_id=". $_SESSION['selected_tags'][0];
383 for($i = 1; $i < count($_SESSION['selected_tags']); $i++) {
385 AND pt". ($i+1) .".tag_id=". $_SESSION['selected_tags'][$i] ."
388 $result = $this->db->db_query($query_str);
391 while($row = $this->db->db_fetch_object($result)) {
392 array_push($tagged_photos, $row['photo_id']);
394 return $tagged_photos;
397 /* return all available photos */
398 $result = $this->db->db_query("
399 SELECT DISTINCT photo_id
405 while($row = $this->db->db_fetch_object($result)) {
406 array_push($tagged_photos, $row['photo_id']);
408 return $tagged_photos;
410 } // getPhotoSelection()
412 public function showPhotoIndex()
414 $photos = $this->getPhotoSelection();
416 $count = count($photos);
418 if(isset($_SESSION['begin_with']) && $_SESSION['begin_with'] != "")
419 $anchor = $_SESSION['begin_with'];
421 if(!isset($this->cfg->rows_per_page) || $this->cfg->rows_per_page == 0) {
427 elseif($this->cfg->rows_per_page > 0) {
429 if(!$_SESSION['begin_with'] || $_SESSION['begin_with'] == 0)
433 $begin_with = $_SESSION['begin_with'];
435 // verify $begin_with - perhaps the thumbs-per-rows or
436 // rows-per-page variables have changed or the jump back
437 // from a photo wasn't exact - so calculate the real new
439 $multiplicator = $this->cfg->rows_per_page * $this->cfg->thumbs_per_row;
440 for($i = 0; $i <= $count; $i+=$multiplicator) {
441 if($begin_with >= $i && $begin_with < $i+$multiplicator) {
448 $end_with = $begin_with + ($this->cfg->rows_per_page * $this->cfg->thumbs_per_row);
454 $images[$rows] = Array();
455 $img_height[$rows] = Array();
456 $img_width[$rows] = Array();
457 $img_id[$rows] = Array();
458 $img_name[$rows] = Array();
460 for($i = $begin_with; $i < $end_with; $i++) {
462 $images[$rows][$cols] = $photos[$i];
463 $img_id[$rows][$cols] = $i;
464 $img_name[$rows][$cols] = $this->getPhotoName($photos[$i]);
466 $thumb_path = $this->cfg->base_path ."/thumbs/". $this->cfg->thumb_width ."_". $this->getMD5($photos[$i]);
468 if(file_exists($thumb_path)) {
469 $info = getimagesize($thumb_path);
470 $img_width[$rows][$cols] = $info[0];
471 $img_height[$rows][$cols] = $info[1];
474 if($cols == $this->cfg->thumbs_per_row-1) {
477 $images[$rows] = Array();
478 $img_width[$rows] = Array();
479 $img_height[$rows] = Array();
486 // +1 for for smarty's selection iteration
489 if(isset($_SESSION['searchfor']) && $_SESSION['searchfor'] != '')
490 $this->tmpl->assign('searchfor', $_SESSION['searchfor']);
492 if($this->cfg->rows_per_page != 0) {
494 /* calculate the page switchers */
495 $previous_start = $begin_with - ($this->cfg->rows_per_page * $this->cfg->thumbs_per_row);
496 $next_start = $begin_with + ($this->cfg->rows_per_page * $this->cfg->thumbs_per_row);
499 $this->tmpl->assign("previous_url", "javascript:showPhotoIndex(". $previous_start .");");
500 if($end_with < $count)
501 $this->tmpl->assign("next_url", "javascript:showPhotoIndex(". $next_start .");");
504 $photo_per_page = $this->cfg->rows_per_page * $this->cfg->thumbs_per_row;
506 /* until 6 pages we show the selector from 1-6
507 everything large will be
508 1 ... 2 3 4 (5) 6 7 ... 9
510 $last_page = ceil($count / $photo_per_page);
512 if($begin_with == 0) {
517 for($i = $begin_with; $i >= 0; $i-=$photo_per_page) {
522 for($i = 1; $i <= $last_page; $i++) {
524 if($current_page == $i)
525 $style = "style=\"font-size: 125%;\"";
526 elseif($current_page-1 == $i || $current_page+1 == $i)
527 $style = "style=\"font-size: 105%;\"";
528 elseif(($current_page-5 >= $i) && ($i != 1) ||
529 ($current_page+5 <= $i) && ($i != $last_page))
530 $style = "style=\"font-size: 75%;\"";
534 $page_select.= "<a href=\"javascript:showPhotoIndex(". (($i*$photo_per_page)-$photo_per_page) .");\"";
536 $page_select.= $style;
537 $page_select.= ">". $i ."</a> ";
541 /* only show the page selector if we have more then one page */
543 $this->tmpl->assign('page_selector', $page_select);
547 if($_SESSION['selected_tags'] != "") {
548 foreach($_SESSION['selected_tags'] as $tag)
549 $current_tags.= $tag .",";
550 $current_tags = substr($current_tags, 0, strlen($current_tags)-1);
553 $extern_link = "http://". $_SERVER['SERVER_NAME'] ."/index.php?mode=showpi";
554 if($current_tags != "") {
555 $extern_link.= "&tags=". $current_tags;
558 $this->tmpl->assign('extern_link', $extern_link);
559 $this->tmpl->assign('count', $count);
560 $this->tmpl->assign('width', $this->cfg->thumb_width);
561 $this->tmpl->assign('images', $images);
562 $this->tmpl->assign('img_width', $img_width);
563 $this->tmpl->assign('img_height', $img_height);
564 $this->tmpl->assign('img_id', $img_id);
565 $this->tmpl->assign('img_name', $img_name);
566 $this->tmpl->assign('rows', $rows);
567 $this->tmpl->assign('columns', $this->cfg->thumbs_per_row);
569 $this->tmpl->show("photo_index.tpl");
572 print "<script language=\"JavaScript\">self.location.hash = '#image". $anchor ."';</script>\n";
574 } // showPhotoIndex()
576 public function showBubbleDetails($photo, $direction)
578 if($direction == "up")
579 $direction = "bubbleimg_up";
581 $direction = "bubbleimg_down";
583 $details = $this->get_photo_details($photo);
584 $orig_path = $this->translate_path($details['directory_path']) ."/". $details['name'];
586 $image_url = "phpfspot_img.php?idx=". $photo ."&width=". $this->cfg->bubble_width;
588 $filesize = filesize($orig_path);
589 $filesize = rand($filesize/1024, 2);
591 if(!file_exists($orig_path)) {
592 $this->_warning("Photo ". $orig_path ." does not exist!<br />\n");
596 if(!is_readable($orig_path)) {
597 $this->_warning("Photo ". $orig_path ." is not readable for user ". get_current_user() ."<br />\n");
601 $img = getimagesize($orig_path);
603 $this->tmpl->assign('file_size', $filesize);
604 $this->tmpl->assign('width', $img[0]);
605 $this->tmpl->assign('height', $img[1]);
606 $this->tmpl->assign('file_name', $details['name']);
607 $this->tmpl->assign('image_id', $direction);
608 $this->tmpl->assign('image_url', $image_url);
609 $this->tmpl->show("bubble_details.tpl");
611 } // showBubbleDetails()
613 public function showCredits()
615 $this->tmpl->assign('version', $this->cfg->version);
616 $this->tmpl->assign('product', $this->cfg->product);
617 $this->tmpl->show("credits.tpl");
621 public function create_thumbnail($orig_image, $thumb_image, $width)
623 if(!file_exists($orig_image))
626 $details = getimagesize($orig_image);
628 /* check if original photo is a support image type */
629 if(!$this->checkifImageSupported($details['mime']))
632 $meta = $this->get_meta_informations($orig_image);
637 switch($meta['Orientation']) {
639 case 1: /* top, left */
640 $rotate = 0; $flip = false; break;
641 case 2: /* top, right */
642 $rotate = 0; $flip = true; break;
643 case 3: /* bottom, left */
644 $rotate = 180; $flip = false; break;
645 case 4: /* bottom, right */
646 $rotate = 180; $flip = true; break;
647 case 5: /* left side, top */
648 $rotate = 90; $flip = true; break;
649 case 6: /* right side, top */
650 $rotate = 90; $flip = false; break;
651 case 7: /* left side, bottom */
652 $rotate = 270; $flip = true; break;
653 case 8: /* right side, bottom */
654 $rotate = 270; $flip = false; break;
657 $src_img = @imagecreatefromjpeg($orig_image);
660 print "Can't load image from ". $orig_image ."\n";
664 /* grabs the height and width */
665 $cur_width = imagesx($src_img);
666 $cur_height = imagesy($src_img);
668 // If requested width is more then the actual image width,
669 // do not generate a thumbnail
671 if($width >= $cur_width) {
672 imagedestroy($src_img);
676 // If the image will be rotate because EXIF orientation said so
677 // 'virtually rotate' the image for further calculations
678 if($rotate == 90 || $rotate == 270) {
680 $cur_width = $cur_height;
684 /* calculates aspect ratio */
685 $aspect_ratio = $cur_height / $cur_width;
688 if($aspect_ratio < 1) {
690 $new_h = abs($new_w * $aspect_ratio);
692 /* 'virtually' rotate the image and calculate it's ratio */
693 $tmp_w = $cur_height;
695 /* now get the ratio from the 'rotated' image */
696 $tmp_ratio = $tmp_h/$tmp_w;
697 /* now calculate the new dimensions */
699 $tmp_h = abs($tmp_w * $tmp_ratio);
701 // now that we know, how high they photo should be, if it
702 // gets rotated, use this high to scale the image
704 $new_w = abs($new_h / $aspect_ratio);
706 // If the image will be rotate because EXIF orientation said so
707 // now 'virtually rotate' back the image for the image manipulation
708 if($rotate == 90 || $rotate == 270) {
715 /* creates new image of that size */
716 $dst_img = imagecreatetruecolor($new_w, $new_h);
718 imagefill($dst_img, 0, 0, ImageColorAllocate($dst_img, 255, 255, 255));
720 /* copies resized portion of original image into new image */
721 imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $new_w, $new_h, imagesx($src_img), imagesy($src_img));
723 /* needs the image to be flipped horizontal? */
727 for($x = 0; $x < $new_w; $x++) {
728 imagecopy($dst_img, $image, $x, 0, $w - $x - 1, 0, 1, $h);
733 $this->_debug("(ROTATE)");
734 $dst_img = $this->rotateImage($dst_img, $rotate);
737 /* write down new generated file */
738 $result = imagejpeg($dst_img, $thumb_image, 75);
741 imagedestroy($dst_img);
742 imagedestroy($src_img);
744 if($result === false) {
745 print "Can't write thumbnail ". $thumb_image ."\n";
751 } // create_thumbnail()
753 public function get_meta_informations($file)
755 return exif_read_data($file);
757 } // get_meta_informations()
759 public function check_config_table()
761 // if the config table doesn't exist yet, create it
762 if(!$this->cfg_db->db_check_table_exists("images")) {
763 $this->cfg_db->db_exec("
764 CREATE TABLE images (
765 img_idx int primary key,
771 } // check_config_table
774 * Generates a thumbnail from photo idx
776 * This function will generate JPEG thumbnails from provided F-Spot photo
779 * 1. Check if all thumbnail generations (width) are already in place and
781 * 2. Check if the md5sum of the original file has changed
782 * 3. Generate the thumbnails if needed
784 public function gen_thumb($idx = 0, $force = 0)
788 $resolutions = Array(
789 $this->cfg->thumb_width,
790 $this->cfg->bubble_width,
791 $this->cfg->photo_width,
794 /* get details from F-Spot's database */
795 $details = $this->get_photo_details($idx);
797 /* calculate file MD5 sum */
798 $full_path = $this->translate_path($details['directory_path']) ."/". $details['name'];
800 if(!file_exists($full_path)) {
801 $this->_warning("File ". $full_path ." does not exist\n");
805 if(!is_readable($full_path)) {
806 $this->_warning("File ". $full_path ." is not readable for ". get_current_user() ."\n");
810 $file_md5 = md5_file($full_path);
812 $this->_debug("Image [". $idx ."] ". $details['name'] ." Thumbnails:");
814 foreach($resolutions as $resolution) {
816 $thumb_path = $this->cfg->base_path ."/thumbs/". $resolution ."_". $file_md5;
818 /* if the thumbnail file doesn't exist, create it */
819 if(!file_exists($thumb_path)) {
821 $this->_debug(" ". $resolution ."px");
822 if(!$this->create_thumbnail($full_path, $thumb_path, $resolution))
826 /* if the file hasn't changed there is no need to regen the thumb */
827 elseif($file_md5 != $this->getMD5($idx) || $force) {
829 $this->_debug(" ". $resolution ."px");
830 if(!$this->create_thumbnail($full_path, $thumb_path, $resolution))
836 /* set the new/changed MD5 sum for the current photo */
838 $this->setMD5($idx, $file_md5);
845 public function getMD5($idx)
847 $result = $this->cfg_db->db_query("
850 WHERE img_idx='". $idx ."'
856 $img = $this->cfg_db->db_fetch_object($result);
857 return $img['img_md5'];
861 private function setMD5($idx, $md5)
863 $result = $this->cfg_db->db_exec("
864 REPLACE INTO images (img_idx, img_md5)
865 VALUES ('". $idx ."', '". $md5 ."')
870 public function setTagCondition($mode)
872 $_SESSION['tag_condition'] = $mode;
874 } // setTagCondition()
876 public function startTagSearch($searchfor)
878 $_SESSION['searchfor'] = $searchfor;
879 $_SESSION['selected_tags'] = Array();
881 foreach($this->avail_tags as $tag) {
882 if(preg_match('/'. $searchfor .'/i', $this->tags[$tag]))
883 array_push($_SESSION['selected_tags'], $tag);
886 } // startTagSearch()
888 private function rotateImage($img, $degrees)
890 if(function_exists("imagerotate"))
891 $img = imagerotate($img, $degrees, 0);
894 function imagerotate($src_img, $angle)
896 $src_x = imagesx($src_img);
897 $src_y = imagesy($src_img);
902 elseif ($src_x <= $src_y) {
906 elseif ($src_x >= $src_y) {
911 $rotate=imagecreatetruecolor($dest_x,$dest_y);
912 imagealphablending($rotate, false);
917 for ($y = 0; $y < ($src_y); $y++) {
918 for ($x = 0; $x < ($src_x); $x++) {
919 $color = imagecolorat($src_img, $x, $y);
920 imagesetpixel($rotate, $dest_x - $y - 1, $x, $color);
926 for ($y = 0; $y < ($src_y); $y++) {
927 for ($x = 0; $x < ($src_x); $x++) {
928 $color = imagecolorat($src_img, $x, $y);
929 imagesetpixel($rotate, $y, $dest_y - $x - 1, $color);
935 for ($y = 0; $y < ($src_y); $y++) {
936 for ($x = 0; $x < ($src_x); $x++) {
937 $color = imagecolorat($src_img, $x, $y);
938 imagesetpixel($rotate, $dest_x - $x - 1, $dest_y - $y - 1, $color);
943 default: $rotate = $src_img;
950 $img = imagerotate($img, $degrees);
958 private function get_photo_tags($idx)
960 $result = $this->db->db_query("
963 INNER JOIN photo_tags pt
965 WHERE pt.photo_id='". $idx ."'
970 while($row = $this->db->db_fetch_object($result))
971 $tags[$row['id']] = $row['name'];
975 } // get_photo_tags()
977 public function showTextImage($txt, $color=000000, $space=4, $font=4, $w=300)
979 if (strlen($color) != 6)
982 $int = hexdec($color);
983 $h = imagefontheight($font);
984 $fw = imagefontwidth($font);
985 $txt = explode("\n", wordwrap($txt, ($w / $fw), "\n"));
986 $lines = count($txt);
987 $im = imagecreate($w, (($h * $lines) + ($lines * $space)));
988 $bg = imagecolorallocate($im, 255, 255, 255);
989 $color = imagecolorallocate($im, 0xFF & ($int >> 0x10), 0xFF & ($int >> 0x8), 0xFF & $int);
992 foreach ($txt as $text) {
993 $x = (($w - ($fw * strlen($text))) / 2);
994 imagestring($im, $font, $x, $y, $text, $color);
998 Header("Content-type: image/png");
1001 } // showTextImage()
1003 private function checkRequirements()
1005 if(!function_exists("imagecreatefromjpeg")) {
1006 print "PHP GD library extension is missing<br />\n";
1010 if(!function_exists("sqlite3_open")) {
1011 print "PHP SQLite3 library extension is missing<br />\n";
1015 /* Check for HTML_AJAX PEAR package, lent from Horde project */
1016 ini_set('track_errors', 1);
1017 @include_once 'HTML/AJAX/Server.php';
1018 if(isset($php_errormsg)) {
1019 print "PEAR HTML_AJAX package is missing<br />\n";
1022 ini_restore('track_errors');
1029 } // checkRequirements()
1031 private function _debug($text)
1033 if($this->fromcmd) {
1039 public function checkifImageSupported($mime)
1041 if(in_array($mime, Array("image/jpeg")))
1046 } // checkifImageSupported()
1048 public function _warning($text)
1050 print "<img src=\"resources/green_info.png\" alt=\"warning\" />\n";