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 $details = $this->get_photo_details($idx);
119 return $details['name'];
123 public function translate_path($path, $width = 0)
125 return str_replace($this->cfg->path_replace_from, $this->cfg->path_replace_to, $path);
129 public function showPhoto($photo)
131 $all_photos = $this->getPhotoSelection();
132 $count = count($all_photos);
134 for($i = 0; $i < $count; $i++) {
137 $next_img = $all_photos[$i];
141 if($all_photos[$i] == $photo) {
145 $previous_img = $all_photos[$i];
148 if($photo == $all_photos[$i]) {
153 $details = $this->get_photo_details($photo);
154 $orig_path = $this->translate_path($details['directory_path']) ."/". $details['name'];
155 $thumb_path = $this->cfg->base_path ."/thumbs/". $this->cfg->photo_width ."_". $this->getMD5($photo);
157 if(!file_exists($orig_path)) {
158 $this->_warning("Photo ". $orig_path ." does not exist!<br />\n");
161 if(!is_readable($orig_path)) {
162 $this->_warning("Photo ". $orig_path ." is not readable for user ". get_current_user() ."<br />\n");
165 /* If the thumbnail doesn't exist yet, try to create it */
166 if(!file_exists($thumb_path)) {
167 $this->gen_thumb($photo, true);
170 $meta = $this->get_meta_informations($orig_path);
172 $meta_date = isset($meta['FileDateTime']) ? strftime("%a %x %X", $meta['FileDateTime']) : "n/a";
173 $meta_make = isset($meta['Make']) ? $meta['Make'] ." ". $meta['Model'] : "n/a";
174 $meta_res = isset($meta['ExifImageWidth']) ? $meta['ExifImageWidth'] ."x". $meta['ExifImageLength'] : "n/a";
175 $meta_size = isset($meta['FileSize']) ? round($meta['FileSize']/1024, 1) ."kbyte" : "n/a";
177 if(file_exists($thumb_path)) {
179 $info = getimagesize($thumb_path);
181 $this->tmpl->assign('description', $details['description']);
182 $this->tmpl->assign('image_name', $details['name']);
184 $this->tmpl->assign('width', $info[0]);
185 $this->tmpl->assign('height', $info[1]);
186 $this->tmpl->assign('ExifMadeOn', $meta_date);
187 $this->tmpl->assign('ExifMadeWith', $meta_make);
188 $this->tmpl->assign('ExifOrigResolution', $meta_res);
189 $this->tmpl->assign('ExifFileSize', $meta_size);
191 $this->tmpl->assign('image_url', 'phpfspot_img.php?idx='. $photo ."&width=". $this->cfg->photo_width);
192 $this->tmpl->assign('image_url_full', 'phpfspot_img.php?idx='. $photo);
194 $this->tmpl->assign('tags', $this->get_photo_tags($photo));
195 $this->tmpl->assign('current', $current);
198 $this->_warning("Can't open file ". $thumb_path ."\n");
202 $this->tmpl->assign('previous_url', "javascript:showImage(". $previous_img .");");
206 $this->tmpl->assign('next_url', "javascript:showImage(". $next_img .");");
209 $this->tmpl->show("single_photo.tpl");
213 public function getAvailableTags()
215 $result = $this->db->db_query("
216 SELECT tag_id as id, count(tag_id) as quantity
226 while($row = $this->db->db_fetch_object($result)) {
227 $tags[$row['id']] = $row['quantity'];
230 // change these font sizes if you will
231 $max_size = 125; // max font size in %
232 $min_size = 75; // min font size in %
234 // get the largest and smallest array values
235 $max_qty = max(array_values($tags));
236 $min_qty = min(array_values($tags));
238 // find the range of values
239 $spread = $max_qty - $min_qty;
240 if (0 == $spread) { // we don't want to divide by zero
244 // determine the font-size increment
245 // this is the increase per tag quantity (times used)
246 $step = ($max_size - $min_size)/($spread);
248 // loop through our tag array
249 foreach ($tags as $key => $value) {
251 if(isset($_SESSION['selected_tags']) && in_array($key, $_SESSION['selected_tags']))
254 // calculate CSS font-size
255 // find the $value in excess of $min_qty
256 // multiply by the font-size increment ($size)
257 // and add the $min_size set above
258 $size = $min_size + (($value - $min_qty) * $step);
259 // uncomment if you want sizes in whole %:
262 print "<a href=\"javascript:Tags('add', ". $key .");\" class=\"tag\" style=\"font-size: ". $size ."%;\">". $this->tags[$key] ."</a>, ";
266 } // getAvailableTags()
268 public function getSelectedTags()
270 foreach($this->avail_tags as $tag)
272 // return all selected tags
273 if(isset($_SESSION['selected_tags']) && in_array($tag, $_SESSION['selected_tags'])) {
274 print "<a href=\"javascript:Tags('del', ". $tag .");\" class=\"tag\">". $this->tags[$tag] ."</a> ";
279 } // getSelectedTags()
281 public function addTag($tag)
283 if(!isset($_SESSION['selected_tags']))
284 $_SESSION['selected_tags'] = Array();
286 if(!in_array($tag, $_SESSION['selected_tags']))
287 array_push($_SESSION['selected_tags'], $tag);
291 public function delTag($tag)
293 if(isset($_SESSION['selected_tags'])) {
294 $key = array_search($tag, $_SESSION['selected_tags']);
295 unset($_SESSION['selected_tags'][$key]);
296 sort($_SESSION['selected_tags']);
301 public function resetTags()
303 unset($_SESSION['selected_tags']);
307 public function resetTagSearch()
309 unset($_SESSION['searchfor']);
311 } // resetTagSearch()
313 public function getPhotoSelection()
315 $tagged_photos = Array();
317 /* return a search result */
318 if(isset($_SESSION['searchfor']) && $_SESSION['searchfor'] != '') {
319 $result = $this->db->db_query("
320 SELECT DISTINCT photo_id
326 WHERE t.name LIKE '%". $_SESSION['searchfor'] ."%'
329 while($row = $this->db->db_fetch_object($result)) {
330 array_push($tagged_photos, $row['photo_id']);
332 return $tagged_photos;
335 /* return according the selected tags */
336 if(isset($_SESSION['selected_tags']) && !empty($_SESSION['selected_tags'])) {
338 foreach($_SESSION['selected_tags'] as $tag)
339 $selected.= $tag .",";
340 $selected = substr($selected, 0, strlen($selected)-1);
342 if($_SESSION['tag_condition'] == 'or') {
343 $result = $this->db->db_query("
344 SELECT DISTINCT photo_id
348 WHERE pt.tag_id IN (". $selected .")
352 elseif($_SESSION['tag_condition'] == 'and') {
354 /* Join together a table looking like
356 pt1.photo_id pt1.tag_id pt2.photo_id pt2.tag_id ...
358 so the query can quickly return all images matching the
359 selected tags in an AND condition
364 SELECT DISTINCT pt1.photo_id
368 for($i = 0; $i < count($_SESSION['selected_tags']); $i++) {
370 INNER JOIN photo_tags pt". ($i+2) ."
371 ON pt1.photo_id=pt". ($i+2) .".photo_id
374 $query_str.= "WHERE pt1.tag_id=". $_SESSION['selected_tags'][0];
375 for($i = 1; $i < count($_SESSION['selected_tags']); $i++) {
377 AND pt". ($i+1) .".tag_id=". $_SESSION['selected_tags'][$i] ."
380 $result = $this->db->db_query($query_str);
383 while($row = $this->db->db_fetch_object($result)) {
384 array_push($tagged_photos, $row['photo_id']);
386 return $tagged_photos;
389 /* return all available photos */
390 $result = $this->db->db_query("
391 SELECT DISTINCT photo_id
397 while($row = $this->db->db_fetch_object($result)) {
398 array_push($tagged_photos, $row['photo_id']);
400 return $tagged_photos;
402 } // getPhotoSelection()
404 public function showPhotoIndex()
406 $photos = $this->getPhotoSelection();
408 $count = count($photos);
410 if(isset($_SESSION['begin_with']) && $_SESSION['begin_with'] != "")
411 $anchor = $_SESSION['begin_with'];
413 if(!isset($this->cfg->rows_per_page) || $this->cfg->rows_per_page == 0) {
419 elseif($this->cfg->rows_per_page > 0) {
421 if(!$_SESSION['begin_with'] || $_SESSION['begin_with'] == 0)
425 $begin_with = $_SESSION['begin_with'];
427 // verify $begin_with - perhaps the thumbs-per-rows or
428 // rows-per-page variables have changed or the jump back
429 // from a photo wasn't exact - so calculate the real new
431 $multiplicator = $this->cfg->rows_per_page * $this->cfg->thumbs_per_row;
432 for($i = 0; $i <= $count; $i+=$multiplicator) {
433 if($begin_with >= $i && $begin_with < $i+$multiplicator) {
440 $end_with = $begin_with + ($this->cfg->rows_per_page * $this->cfg->thumbs_per_row);
446 $images[$rows] = Array();
447 $img_height[$rows] = Array();
448 $img_width[$rows] = Array();
449 $img_id[$rows] = Array();
450 $img_name[$rows] = Array();
452 for($i = $begin_with; $i < $end_with; $i++) {
454 $images[$rows][$cols] = $photos[$i];
455 $img_id[$rows][$cols] = $i;
456 $img_name[$rows][$cols] = $this->getPhotoName($photos[$i]);
458 $thumb_path = $this->cfg->base_path ."/thumbs/". $this->cfg->thumb_width ."_". $this->getMD5($photos[$i]);
460 if(file_exists($thumb_path)) {
461 $info = getimagesize($thumb_path);
462 $img_width[$rows][$cols] = $info[0];
463 $img_height[$rows][$cols] = $info[1];
466 if($cols == $this->cfg->thumbs_per_row-1) {
469 $images[$rows] = Array();
470 $img_width[$rows] = Array();
471 $img_height[$rows] = Array();
478 // +1 for for smarty's selection iteration
481 if(isset($_SESSION['searchfor']) && $_SESSION['searchfor'] != '')
482 $this->tmpl->assign('searchfor', $_SESSION['searchfor']);
484 if($this->cfg->rows_per_page != 0) {
486 /* calculate the page switchers */
487 $previous_start = $begin_with - ($this->cfg->rows_per_page * $this->cfg->thumbs_per_row);
488 $next_start = $begin_with + ($this->cfg->rows_per_page * $this->cfg->thumbs_per_row);
491 $this->tmpl->assign("previous_url", "javascript:showPhotoIndex(". $previous_start .");");
492 if($end_with < $count)
493 $this->tmpl->assign("next_url", "javascript:showPhotoIndex(". $next_start .");");
496 $photo_per_page = $this->cfg->rows_per_page * $this->cfg->thumbs_per_row;
498 /* until 6 pages we show the selector from 1-6
499 everything large will be
500 1 ... 2 3 4 (5) 6 7 ... 9
502 $last_page = ceil($count / $photo_per_page);
504 if($begin_with == 0) {
509 for($i = $begin_with; $i >= 0; $i-=$photo_per_page) {
514 for($i = 1; $i <= $last_page; $i++) {
516 if($current_page == $i)
517 $style = "style=\"font-size: 125%;\"";
518 elseif($current_page-1 == $i || $current_page+1 == $i)
519 $style = "style=\"font-size: 105%;\"";
520 elseif(($current_page-5 >= $i) && ($i != 1) ||
521 ($current_page+5 <= $i) && ($i != $last_page))
522 $style = "style=\"font-size: 75%;\"";
526 $page_select.= "<a href=\"javascript:showPhotoIndex(". (($i*$photo_per_page)-$photo_per_page) .");\"";
528 $page_select.= $style;
529 $page_select.= ">". $i ."</a> ";
533 /* only show the page selector if we have more then one page */
535 $this->tmpl->assign('page_selector', $page_select);
539 if($_SESSION['selected_tags'] != "") {
540 foreach($_SESSION['selected_tags'] as $tag)
541 $current_tags.= $tag .",";
542 $current_tags = substr($current_tags, 0, strlen($current_tags)-1);
545 $extern_link = "http://". $_SERVER['SERVER_NAME'] ."/index.php?mode=showpi";
546 if($current_tags != "") {
547 $extern_link.= "&tags=". $current_tags;
550 $this->tmpl->assign('extern_link', $extern_link);
551 $this->tmpl->assign('count', $count);
552 $this->tmpl->assign('width', $this->cfg->thumb_width);
553 $this->tmpl->assign('images', $images);
554 $this->tmpl->assign('img_width', $img_width);
555 $this->tmpl->assign('img_height', $img_height);
556 $this->tmpl->assign('img_id', $img_id);
557 $this->tmpl->assign('img_name', $img_name);
558 $this->tmpl->assign('rows', $rows);
559 $this->tmpl->assign('columns', $this->cfg->thumbs_per_row);
561 $this->tmpl->show("photo_index.tpl");
564 print "<script language=\"JavaScript\">self.location.hash = '#image". $anchor ."';</script>\n";
566 } // showPhotoIndex()
568 public function showBubbleDetails($photo, $direction)
570 if($direction == "up")
571 $direction = "bubbleimg_up";
573 $direction = "bubbleimg_down";
575 $details = $this->get_photo_details($photo);
576 $orig_path = $this->translate_path($details['directory_path']) ."/". $details['name'];
578 $image_url = "phpfspot_img.php?idx=". $photo ."&width=". $this->cfg->bubble_width;
580 $filesize = filesize($orig_path);
581 $filesize = rand($filesize/1024, 2);
583 if(!file_exists($orig_path)) {
584 $this->_warning("Photo ". $orig_path ." does not exist!<br />\n");
588 if(!is_readable($orig_path)) {
589 $this->_warning("Photo ". $orig_path ." is not readable for user ". get_current_user() ."<br />\n");
593 $img = getimagesize($orig_path);
595 $this->tmpl->assign('file_size', $filesize);
596 $this->tmpl->assign('width', $img[0]);
597 $this->tmpl->assign('height', $img[1]);
598 $this->tmpl->assign('file_name', $details['name']);
599 $this->tmpl->assign('image_id', $direction);
600 $this->tmpl->assign('image_url', $image_url);
601 $this->tmpl->show("bubble_details.tpl");
603 } // showBubbleDetails()
605 public function showCredits()
607 $this->tmpl->assign('version', $this->cfg->version);
608 $this->tmpl->assign('product', $this->cfg->product);
609 $this->tmpl->show("credits.tpl");
613 public function create_thumbnail($orig_image, $thumb_image, $width)
615 if(!file_exists($orig_image))
618 $details = getimagesize($orig_image);
620 /* check if original photo is a support image type */
621 if(!$this->checkifImageSupported($details['mime']))
624 $meta = $this->get_meta_informations($orig_image);
629 switch($meta['Orientation']) {
631 case 1: /* top, left */
632 $rotate = 0; $flip = false; break;
633 case 2: /* top, right */
634 $rotate = 0; $flip = true; break;
635 case 3: /* bottom, left */
636 $rotate = 180; $flip = false; break;
637 case 4: /* bottom, right */
638 $rotate = 180; $flip = true; break;
639 case 5: /* left side, top */
640 $rotate = 90; $flip = true; break;
641 case 6: /* right side, top */
642 $rotate = 90; $flip = false; break;
643 case 7: /* left side, bottom */
644 $rotate = 270; $flip = true; break;
645 case 8: /* right side, bottom */
646 $rotate = 270; $flip = false; break;
649 $src_img = @imagecreatefromjpeg($orig_image);
652 print "Can't load image from ". $orig_image ."\n";
656 /* grabs the height and width */
657 $cur_width = imagesx($src_img);
658 $cur_height = imagesy($src_img);
660 // If requested width is more then the actual image width,
661 // do not generate a thumbnail
663 if($width >= $cur_width) {
664 imagedestroy($src_img);
668 // If the image will be rotate because EXIF orientation said so
669 // 'virtually rotate' the image for further calculations
670 if($rotate == 90 || $rotate == 270) {
672 $cur_width = $cur_height;
676 /* calculates aspect ratio */
677 $aspect_ratio = $cur_height / $cur_width;
680 if($aspect_ratio < 1) {
682 $new_h = abs($new_w * $aspect_ratio);
684 /* 'virtually' rotate the image and calculate it's ratio */
685 $tmp_w = $cur_height;
687 /* now get the ratio from the 'rotated' image */
688 $tmp_ratio = $tmp_h/$tmp_w;
689 /* now calculate the new dimensions */
691 $tmp_h = abs($tmp_w * $tmp_ratio);
693 // now that we know, how high they photo should be, if it
694 // gets rotated, use this high to scale the image
696 $new_w = abs($new_h / $aspect_ratio);
698 // If the image will be rotate because EXIF orientation said so
699 // now 'virtually rotate' back the image for the image manipulation
700 if($rotate == 90 || $rotate == 270) {
707 /* creates new image of that size */
708 $dst_img = imagecreatetruecolor($new_w, $new_h);
710 imagefill($dst_img, 0, 0, ImageColorAllocate($dst_img, 255, 255, 255));
712 /* copies resized portion of original image into new image */
713 imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $new_w, $new_h, imagesx($src_img), imagesy($src_img));
715 /* needs the image to be flipped horizontal? */
719 for($x = 0; $x < $new_w; $x++) {
720 imagecopy($dst_img, $image, $x, 0, $w - $x - 1, 0, 1, $h);
725 $this->_debug("(ROTATE)");
726 $dst_img = $this->rotateImage($dst_img, $rotate);
729 /* write down new generated file */
730 $result = imagejpeg($dst_img, $thumb_image, 75);
733 imagedestroy($dst_img);
734 imagedestroy($src_img);
736 if($result === false) {
737 print "Can't write thumbnail ". $thumb_image ."\n";
743 } // create_thumbnail()
745 public function get_meta_informations($file)
747 return exif_read_data($file);
749 } // get_meta_informations()
751 public function check_config_table()
753 // if the config table doesn't exist yet, create it
754 if(!$this->cfg_db->db_check_table_exists("images")) {
755 $this->cfg_db->db_exec("
756 CREATE TABLE images (
757 img_idx int primary key,
763 } // check_config_table
766 * Generates a thumbnail from photo idx
768 * This function will generate JPEG thumbnails from provided F-Spot photo
771 * 1. Check if all thumbnail generations (width) are already in place and
773 * 2. Check if the md5sum of the original file has changed
774 * 3. Generate the thumbnails if needed
776 public function gen_thumb($idx = 0, $force = 0)
780 $resolutions = Array(
781 $this->cfg->thumb_width,
782 $this->cfg->bubble_width,
783 $this->cfg->photo_width,
786 /* get details from F-Spot's database */
787 $details = $this->get_photo_details($idx);
789 /* calculate file MD5 sum */
790 $full_path = $this->translate_path($details['directory_path']) ."/". $details['name'];
792 if(!file_exists($full_path)) {
793 $this->_warning("File ". $full_path ." does not exist\n");
797 if(!is_readable($full_path)) {
798 $this->_warning("File ". $full_path ." is not readable for ". get_current_user() ."\n");
802 $file_md5 = md5_file($full_path);
804 $this->_debug("Image [". $idx ."] ". $details['name'] ." Thumbnails:");
806 foreach($resolutions as $resolution) {
808 $thumb_path = $this->cfg->base_path ."/thumbs/". $resolution ."_". $file_md5;
810 /* if the thumbnail file doesn't exist, create it */
811 if(!file_exists($thumb_path)) {
813 $this->_debug(" ". $resolution ."px");
814 if(!$this->create_thumbnail($full_path, $thumb_path, $resolution))
818 /* if the file hasn't changed there is no need to regen the thumb */
819 elseif($file_md5 != $this->getMD5($idx) || $force) {
821 $this->_debug(" ". $resolution ."px");
822 if(!$this->create_thumbnail($full_path, $thumb_path, $resolution))
828 /* set the new/changed MD5 sum for the current photo */
830 $this->setMD5($idx, $file_md5);
837 public function getMD5($idx)
839 $result = $this->cfg_db->db_query("
842 WHERE img_idx='". $idx ."'
848 $img = $this->cfg_db->db_fetch_object($result);
849 return $img['img_md5'];
853 private function setMD5($idx, $md5)
855 $result = $this->cfg_db->db_exec("
856 REPLACE INTO images (img_idx, img_md5)
857 VALUES ('". $idx ."', '". $md5 ."')
862 public function setTagCondition($mode)
864 $_SESSION['tag_condition'] = $mode;
866 } // setTagCondition()
868 public function startTagSearch($searchfor)
870 $_SESSION['searchfor'] = $searchfor;
871 $_SESSION['selected_tags'] = Array();
873 foreach($this->avail_tags as $tag) {
874 if(preg_match('/'. $searchfor .'/i', $this->tags[$tag]))
875 array_push($_SESSION['selected_tags'], $tag);
878 } // startTagSearch()
880 private function rotateImage($img, $degrees)
882 if(function_exists("imagerotate"))
883 $img = imagerotate($img, $degrees, 0);
886 function imagerotate($src_img, $angle)
888 $src_x = imagesx($src_img);
889 $src_y = imagesy($src_img);
894 elseif ($src_x <= $src_y) {
898 elseif ($src_x >= $src_y) {
903 $rotate=imagecreatetruecolor($dest_x,$dest_y);
904 imagealphablending($rotate, false);
909 for ($y = 0; $y < ($src_y); $y++) {
910 for ($x = 0; $x < ($src_x); $x++) {
911 $color = imagecolorat($src_img, $x, $y);
912 imagesetpixel($rotate, $dest_x - $y - 1, $x, $color);
918 for ($y = 0; $y < ($src_y); $y++) {
919 for ($x = 0; $x < ($src_x); $x++) {
920 $color = imagecolorat($src_img, $x, $y);
921 imagesetpixel($rotate, $y, $dest_y - $x - 1, $color);
927 for ($y = 0; $y < ($src_y); $y++) {
928 for ($x = 0; $x < ($src_x); $x++) {
929 $color = imagecolorat($src_img, $x, $y);
930 imagesetpixel($rotate, $dest_x - $x - 1, $dest_y - $y - 1, $color);
935 default: $rotate = $src_img;
942 $img = imagerotate($img, $degrees);
950 private function get_photo_tags($idx)
952 $result = $this->db->db_query("
955 INNER JOIN photo_tags pt
957 WHERE pt.photo_id='". $idx ."'
962 while($row = $this->db->db_fetch_object($result))
963 $tags[$row['id']] = $row['name'];
967 } // get_photo_tags()
969 public function showTextImage($txt, $color=000000, $space=4, $font=4, $w=300)
971 if (strlen($color) != 6)
974 $int = hexdec($color);
975 $h = imagefontheight($font);
976 $fw = imagefontwidth($font);
977 $txt = explode("\n", wordwrap($txt, ($w / $fw), "\n"));
978 $lines = count($txt);
979 $im = imagecreate($w, (($h * $lines) + ($lines * $space)));
980 $bg = imagecolorallocate($im, 255, 255, 255);
981 $color = imagecolorallocate($im, 0xFF & ($int >> 0x10), 0xFF & ($int >> 0x8), 0xFF & $int);
984 foreach ($txt as $text) {
985 $x = (($w - ($fw * strlen($text))) / 2);
986 imagestring($im, $font, $x, $y, $text, $color);
990 Header("Content-type: image/png");
995 private function checkRequirements()
997 if(!function_exists("imagecreatefromjpeg")) {
998 print "PHP GD library extension is missing<br />\n";
1002 if(!function_exists("sqlite3_open")) {
1003 print "PHP SQLite3 library extension is missing<br />\n";
1007 /* Check for HTML_AJAX PEAR package, lent from Horde project */
1008 ini_set('track_errors', 1);
1009 @include_once 'HTML/AJAX/Server.php';
1010 if(isset($php_errormsg)) {
1011 print "PEAR HTML_AJAX package is missing<br />\n";
1014 ini_restore('track_errors');
1021 } // checkRequirements()
1023 private function _debug($text)
1025 if($this->fromcmd) {
1031 public function checkifImageSupported($mime)
1033 if(in_array($mime, Array("image/jpeg")))
1038 } // checkifImageSupported()
1040 public function _warning($text)
1042 print "<img src=\"resources/green_info.png\" alt=\"warning\" />\n";