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']);
58 $this->tmpl->assign('from_date', $this->get_calendar());
59 $this->tmpl->assign('to_date', $this->get_calendar());
61 switch($_GET['mode']) {
63 if(isset($_GET['tags'])) {
64 $_SESSION['selected_tags'] = split(',', $_GET['tags']);
69 $this->tmpl->assign('content_page', 'welcome.tpl');
70 $this->tmpl->show("index.tpl");
75 private function get_tags()
78 $this->avail_tags = Array();
81 $result = $this->db->db_query("
84 ORDER BY sort_priority ASC
87 while($row = $this->db->db_fetch_object($result)) {
90 $tag_name = $row['name'];
92 /* check if config requests to ignore this tag */
93 if(in_array($row['name'], $this->cfg->hide_tags))
96 $this->tags[$tag_id] = $tag_name;
97 $this->avail_tags[$count] = $tag_id;
105 public function get_photo_details($idx)
107 $result = $this->db->db_query("
110 WHERE id='". $idx ."'
113 return $this->db->db_fetch_object($result);
115 } // get_photo_details
117 public function getPhotoName($idx)
119 if($details = $this->get_photo_details($idx)) {
121 $name = $details['name'];
123 if(strlen($name) > 15) {
124 $name = substr($name, 0, 10) ."...". substr($name, -10);
133 public function translate_path($path, $width = 0)
135 return str_replace($this->cfg->path_replace_from, $this->cfg->path_replace_to, $path);
139 public function showPhoto($photo)
141 $all_photos = $this->getPhotoSelection();
142 $count = count($all_photos);
144 for($i = 0; $i < $count; $i++) {
147 $next_img = $all_photos[$i];
151 if($all_photos[$i] == $photo) {
155 $previous_img = $all_photos[$i];
158 if($photo == $all_photos[$i]) {
163 $details = $this->get_photo_details($photo);
164 $orig_path = $this->translate_path($details['directory_path']) ."/". $details['name'];
165 $thumb_path = $this->cfg->base_path ."/thumbs/". $this->cfg->photo_width ."_". $this->getMD5($photo);
167 if(!file_exists($orig_path)) {
168 $this->_warning("Photo ". $orig_path ." does not exist!<br />\n");
171 if(!is_readable($orig_path)) {
172 $this->_warning("Photo ". $orig_path ." is not readable for user ". get_current_user() ."<br />\n");
175 /* If the thumbnail doesn't exist yet, try to create it */
176 if(!file_exists($thumb_path)) {
177 $this->gen_thumb($photo, true);
180 $meta = $this->get_meta_informations($orig_path);
182 /* If EXIF data are available, use them */
183 if(isset($meta['ExifImageWidth'])) {
184 $meta_res = $meta['ExifImageWidth'] ."x". $meta['ExifImageLength'];
186 $info = getimagesize($orig_path);
187 $meta_res = $info[0] ."x". $info[1];
190 $meta_date = isset($meta['FileDateTime']) ? strftime("%a %x %X", $meta['FileDateTime']) : "n/a";
191 $meta_make = isset($meta['Make']) ? $meta['Make'] ." ". $meta['Model'] : "n/a";
192 $meta_size = isset($meta['FileSize']) ? round($meta['FileSize']/1024, 1) ."kbyte" : "n/a";
194 if(file_exists($thumb_path)) {
196 $info = getimagesize($thumb_path);
198 $this->tmpl->assign('description', $details['description']);
199 $this->tmpl->assign('image_name', $details['name']);
201 $this->tmpl->assign('width', $info[0]);
202 $this->tmpl->assign('height', $info[1]);
203 $this->tmpl->assign('ExifMadeOn', $meta_date);
204 $this->tmpl->assign('ExifMadeWith', $meta_make);
205 $this->tmpl->assign('ExifOrigResolution', $meta_res);
206 $this->tmpl->assign('ExifFileSize', $meta_size);
208 $this->tmpl->assign('image_url', 'phpfspot_img.php?idx='. $photo ."&width=". $this->cfg->photo_width);
209 $this->tmpl->assign('image_url_full', 'phpfspot_img.php?idx='. $photo);
211 $this->tmpl->assign('tags', $this->get_photo_tags($photo));
212 $this->tmpl->assign('current', $current);
215 $this->_warning("Can't open file ". $thumb_path ."\n");
219 $this->tmpl->assign('previous_url', "javascript:showImage(". $previous_img .");");
223 $this->tmpl->assign('next_url', "javascript:showImage(". $next_img .");");
226 $this->tmpl->show("single_photo.tpl");
230 public function getAvailableTags()
232 $result = $this->db->db_query("
233 SELECT tag_id as id, count(tag_id) as quantity
243 while($row = $this->db->db_fetch_object($result)) {
244 $tags[$row['id']] = $row['quantity'];
247 // change these font sizes if you will
248 $max_size = 125; // max font size in %
249 $min_size = 75; // min font size in %
251 // get the largest and smallest array values
252 $max_qty = max(array_values($tags));
253 $min_qty = min(array_values($tags));
255 // find the range of values
256 $spread = $max_qty - $min_qty;
257 if (0 == $spread) { // we don't want to divide by zero
261 // determine the font-size increment
262 // this is the increase per tag quantity (times used)
263 $step = ($max_size - $min_size)/($spread);
265 // loop through our tag array
266 foreach ($tags as $key => $value) {
268 if(isset($_SESSION['selected_tags']) && in_array($key, $_SESSION['selected_tags']))
271 // calculate CSS font-size
272 // find the $value in excess of $min_qty
273 // multiply by the font-size increment ($size)
274 // and add the $min_size set above
275 $size = $min_size + (($value - $min_qty) * $step);
276 // uncomment if you want sizes in whole %:
279 print "<a href=\"javascript:Tags('add', ". $key .");\" class=\"tag\" style=\"font-size: ". $size ."%;\">". $this->tags[$key] ."</a>, ";
283 } // getAvailableTags()
285 public function getSelectedTags()
287 foreach($this->avail_tags as $tag)
289 // return all selected tags
290 if(isset($_SESSION['selected_tags']) && in_array($tag, $_SESSION['selected_tags'])) {
291 print "<a href=\"javascript:Tags('del', ". $tag .");\" class=\"tag\">". $this->tags[$tag] ."</a> ";
296 } // getSelectedTags()
298 public function addTag($tag)
300 if(!isset($_SESSION['selected_tags']))
301 $_SESSION['selected_tags'] = Array();
303 if(!in_array($tag, $_SESSION['selected_tags']))
304 array_push($_SESSION['selected_tags'], $tag);
308 public function delTag($tag)
310 if(isset($_SESSION['selected_tags'])) {
311 $key = array_search($tag, $_SESSION['selected_tags']);
312 unset($_SESSION['selected_tags'][$key]);
313 sort($_SESSION['selected_tags']);
318 public function resetTags()
320 unset($_SESSION['selected_tags']);
324 public function resetTagSearch()
326 unset($_SESSION['searchfor']);
328 } // resetTagSearch()
330 public function getPhotoSelection()
332 $tagged_photos = Array();
334 /* return a search result */
335 if(isset($_SESSION['searchfor']) && $_SESSION['searchfor'] != '') {
336 $result = $this->db->db_query("
337 SELECT DISTINCT photo_id
343 WHERE t.name LIKE '%". $_SESSION['searchfor'] ."%'
346 while($row = $this->db->db_fetch_object($result)) {
347 array_push($tagged_photos, $row['photo_id']);
349 return $tagged_photos;
352 /* return according the selected tags */
353 if(isset($_SESSION['selected_tags']) && !empty($_SESSION['selected_tags'])) {
355 foreach($_SESSION['selected_tags'] as $tag)
356 $selected.= $tag .",";
357 $selected = substr($selected, 0, strlen($selected)-1);
359 if($_SESSION['tag_condition'] == 'or') {
360 $result = $this->db->db_query("
361 SELECT DISTINCT photo_id
365 WHERE pt.tag_id IN (". $selected .")
369 elseif($_SESSION['tag_condition'] == 'and') {
371 /* Join together a table looking like
373 pt1.photo_id pt1.tag_id pt2.photo_id pt2.tag_id ...
375 so the query can quickly return all images matching the
376 selected tags in an AND condition
381 SELECT DISTINCT pt1.photo_id
385 for($i = 0; $i < count($_SESSION['selected_tags']); $i++) {
387 INNER JOIN photo_tags pt". ($i+2) ."
388 ON pt1.photo_id=pt". ($i+2) .".photo_id
391 $query_str.= "WHERE pt1.tag_id=". $_SESSION['selected_tags'][0];
392 for($i = 1; $i < count($_SESSION['selected_tags']); $i++) {
394 AND pt". ($i+1) .".tag_id=". $_SESSION['selected_tags'][$i] ."
397 $result = $this->db->db_query($query_str);
400 while($row = $this->db->db_fetch_object($result)) {
401 array_push($tagged_photos, $row['photo_id']);
403 return $tagged_photos;
406 /* return all available photos */
407 $result = $this->db->db_query("
408 SELECT DISTINCT photo_id
414 while($row = $this->db->db_fetch_object($result)) {
415 array_push($tagged_photos, $row['photo_id']);
417 return $tagged_photos;
419 } // getPhotoSelection()
421 public function showPhotoIndex()
423 $photos = $this->getPhotoSelection();
425 $count = count($photos);
427 if(isset($_SESSION['begin_with']) && $_SESSION['begin_with'] != "")
428 $anchor = $_SESSION['begin_with'];
430 if(!isset($this->cfg->rows_per_page) || $this->cfg->rows_per_page == 0) {
436 elseif($this->cfg->rows_per_page > 0) {
438 if(!$_SESSION['begin_with'] || $_SESSION['begin_with'] == 0)
442 $begin_with = $_SESSION['begin_with'];
444 // verify $begin_with - perhaps the thumbs-per-rows or
445 // rows-per-page variables have changed or the jump back
446 // from a photo wasn't exact - so calculate the real new
448 $multiplicator = $this->cfg->rows_per_page * $this->cfg->thumbs_per_row;
449 for($i = 0; $i <= $count; $i+=$multiplicator) {
450 if($begin_with >= $i && $begin_with < $i+$multiplicator) {
457 $end_with = $begin_with + ($this->cfg->rows_per_page * $this->cfg->thumbs_per_row);
463 $images[$rows] = Array();
464 $img_height[$rows] = Array();
465 $img_width[$rows] = Array();
466 $img_id[$rows] = Array();
467 $img_name[$rows] = Array();
469 for($i = $begin_with; $i < $end_with; $i++) {
471 $images[$rows][$cols] = $photos[$i];
472 $img_id[$rows][$cols] = $i;
473 $img_name[$rows][$cols] = $this->getPhotoName($photos[$i]);
475 $thumb_path = $this->cfg->base_path ."/thumbs/". $this->cfg->thumb_width ."_". $this->getMD5($photos[$i]);
477 if(file_exists($thumb_path)) {
478 $info = getimagesize($thumb_path);
479 $img_width[$rows][$cols] = $info[0];
480 $img_height[$rows][$cols] = $info[1];
483 if($cols == $this->cfg->thumbs_per_row-1) {
486 $images[$rows] = Array();
487 $img_width[$rows] = Array();
488 $img_height[$rows] = Array();
495 // +1 for for smarty's selection iteration
498 if(isset($_SESSION['searchfor']) && $_SESSION['searchfor'] != '')
499 $this->tmpl->assign('searchfor', $_SESSION['searchfor']);
501 if($this->cfg->rows_per_page != 0) {
503 /* calculate the page switchers */
504 $previous_start = $begin_with - ($this->cfg->rows_per_page * $this->cfg->thumbs_per_row);
505 $next_start = $begin_with + ($this->cfg->rows_per_page * $this->cfg->thumbs_per_row);
508 $this->tmpl->assign("previous_url", "javascript:showPhotoIndex(". $previous_start .");");
509 if($end_with < $count)
510 $this->tmpl->assign("next_url", "javascript:showPhotoIndex(". $next_start .");");
513 $photo_per_page = $this->cfg->rows_per_page * $this->cfg->thumbs_per_row;
515 /* until 6 pages we show the selector from 1-6
516 everything large will be
517 1 ... 2 3 4 (5) 6 7 ... 9
519 $last_page = ceil($count / $photo_per_page);
521 if($begin_with == 0) {
526 for($i = $begin_with; $i >= 0; $i-=$photo_per_page) {
531 for($i = 1; $i <= $last_page; $i++) {
533 if($current_page == $i)
534 $style = "style=\"font-size: 125%;\"";
535 elseif($current_page-1 == $i || $current_page+1 == $i)
536 $style = "style=\"font-size: 105%;\"";
537 elseif(($current_page-5 >= $i) && ($i != 1) ||
538 ($current_page+5 <= $i) && ($i != $last_page))
539 $style = "style=\"font-size: 75%;\"";
543 $page_select.= "<a href=\"javascript:showPhotoIndex(". (($i*$photo_per_page)-$photo_per_page) .");\"";
545 $page_select.= $style;
546 $page_select.= ">". $i ."</a> ";
550 /* only show the page selector if we have more then one page */
552 $this->tmpl->assign('page_selector', $page_select);
556 if($_SESSION['selected_tags'] != "") {
557 foreach($_SESSION['selected_tags'] as $tag)
558 $current_tags.= $tag .",";
559 $current_tags = substr($current_tags, 0, strlen($current_tags)-1);
562 $extern_link = "http://". $_SERVER['SERVER_NAME'] ."/index.php?mode=showpi";
563 if($current_tags != "") {
564 $extern_link.= "&tags=". $current_tags;
567 $this->tmpl->assign('extern_link', $extern_link);
568 $this->tmpl->assign('count', $count);
569 $this->tmpl->assign('width', $this->cfg->thumb_width);
570 $this->tmpl->assign('images', $images);
571 $this->tmpl->assign('img_width', $img_width);
572 $this->tmpl->assign('img_height', $img_height);
573 $this->tmpl->assign('img_id', $img_id);
574 $this->tmpl->assign('img_name', $img_name);
575 $this->tmpl->assign('rows', $rows);
576 $this->tmpl->assign('columns', $this->cfg->thumbs_per_row);
578 $this->tmpl->show("photo_index.tpl");
581 print "<script language=\"JavaScript\">self.location.hash = '#image". $anchor ."';</script>\n";
583 } // showPhotoIndex()
585 public function showBubbleDetails($photo, $direction)
587 if($direction == "up")
588 $direction = "bubbleimg_up";
590 $direction = "bubbleimg_down";
592 $details = $this->get_photo_details($photo);
593 $orig_path = $this->translate_path($details['directory_path']) ."/". $details['name'];
595 $image_url = "phpfspot_img.php?idx=". $photo ."&width=". $this->cfg->bubble_width;
597 $filesize = filesize($orig_path);
598 $filesize = rand($filesize/1024, 2);
600 if(!file_exists($orig_path)) {
601 $this->_warning("Photo ". $orig_path ." does not exist!<br />\n");
605 if(!is_readable($orig_path)) {
606 $this->_warning("Photo ". $orig_path ." is not readable for user ". get_current_user() ."<br />\n");
610 $img = getimagesize($orig_path);
612 $this->tmpl->assign('file_size', $filesize);
613 $this->tmpl->assign('width', $img[0]);
614 $this->tmpl->assign('height', $img[1]);
615 $this->tmpl->assign('file_name', $details['name']);
616 $this->tmpl->assign('image_id', $direction);
617 $this->tmpl->assign('image_url', $image_url);
618 $this->tmpl->show("bubble_details.tpl");
620 } // showBubbleDetails()
622 public function showCredits()
624 $this->tmpl->assign('version', $this->cfg->version);
625 $this->tmpl->assign('product', $this->cfg->product);
626 $this->tmpl->show("credits.tpl");
630 public function create_thumbnail($orig_image, $thumb_image, $width)
632 if(!file_exists($orig_image))
635 $details = getimagesize($orig_image);
637 /* check if original photo is a support image type */
638 if(!$this->checkifImageSupported($details['mime']))
641 $meta = $this->get_meta_informations($orig_image);
646 switch($meta['Orientation']) {
648 case 1: /* top, left */
649 $rotate = 0; $flip = false; break;
650 case 2: /* top, right */
651 $rotate = 0; $flip = true; break;
652 case 3: /* bottom, left */
653 $rotate = 180; $flip = false; break;
654 case 4: /* bottom, right */
655 $rotate = 180; $flip = true; break;
656 case 5: /* left side, top */
657 $rotate = 90; $flip = true; break;
658 case 6: /* right side, top */
659 $rotate = 90; $flip = false; break;
660 case 7: /* left side, bottom */
661 $rotate = 270; $flip = true; break;
662 case 8: /* right side, bottom */
663 $rotate = 270; $flip = false; break;
666 $src_img = @imagecreatefromjpeg($orig_image);
669 print "Can't load image from ". $orig_image ."\n";
673 /* grabs the height and width */
674 $cur_width = imagesx($src_img);
675 $cur_height = imagesy($src_img);
677 // If requested width is more then the actual image width,
678 // do not generate a thumbnail
680 if($width >= $cur_width) {
681 imagedestroy($src_img);
685 // If the image will be rotate because EXIF orientation said so
686 // 'virtually rotate' the image for further calculations
687 if($rotate == 90 || $rotate == 270) {
689 $cur_width = $cur_height;
693 /* calculates aspect ratio */
694 $aspect_ratio = $cur_height / $cur_width;
697 if($aspect_ratio < 1) {
699 $new_h = abs($new_w * $aspect_ratio);
701 /* 'virtually' rotate the image and calculate it's ratio */
702 $tmp_w = $cur_height;
704 /* now get the ratio from the 'rotated' image */
705 $tmp_ratio = $tmp_h/$tmp_w;
706 /* now calculate the new dimensions */
708 $tmp_h = abs($tmp_w * $tmp_ratio);
710 // now that we know, how high they photo should be, if it
711 // gets rotated, use this high to scale the image
713 $new_w = abs($new_h / $aspect_ratio);
715 // If the image will be rotate because EXIF orientation said so
716 // now 'virtually rotate' back the image for the image manipulation
717 if($rotate == 90 || $rotate == 270) {
724 /* creates new image of that size */
725 $dst_img = imagecreatetruecolor($new_w, $new_h);
727 imagefill($dst_img, 0, 0, ImageColorAllocate($dst_img, 255, 255, 255));
729 /* copies resized portion of original image into new image */
730 imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $new_w, $new_h, imagesx($src_img), imagesy($src_img));
732 /* needs the image to be flipped horizontal? */
736 for($x = 0; $x < $new_w; $x++) {
737 imagecopy($dst_img, $image, $x, 0, $w - $x - 1, 0, 1, $h);
742 $this->_debug("(ROTATE)");
743 $dst_img = $this->rotateImage($dst_img, $rotate);
746 /* write down new generated file */
747 $result = imagejpeg($dst_img, $thumb_image, 75);
750 imagedestroy($dst_img);
751 imagedestroy($src_img);
753 if($result === false) {
754 print "Can't write thumbnail ". $thumb_image ."\n";
760 } // create_thumbnail()
762 public function get_meta_informations($file)
764 return exif_read_data($file);
766 } // get_meta_informations()
768 public function check_config_table()
770 // if the config table doesn't exist yet, create it
771 if(!$this->cfg_db->db_check_table_exists("images")) {
772 $this->cfg_db->db_exec("
773 CREATE TABLE images (
774 img_idx int primary key,
780 } // check_config_table
783 * Generates a thumbnail from photo idx
785 * This function will generate JPEG thumbnails from provided F-Spot photo
788 * 1. Check if all thumbnail generations (width) are already in place and
790 * 2. Check if the md5sum of the original file has changed
791 * 3. Generate the thumbnails if needed
793 public function gen_thumb($idx = 0, $force = 0)
797 $resolutions = Array(
798 $this->cfg->thumb_width,
799 $this->cfg->bubble_width,
800 $this->cfg->photo_width,
803 /* get details from F-Spot's database */
804 $details = $this->get_photo_details($idx);
806 /* calculate file MD5 sum */
807 $full_path = $this->translate_path($details['directory_path']) ."/". $details['name'];
809 if(!file_exists($full_path)) {
810 $this->_warning("File ". $full_path ." does not exist\n");
814 if(!is_readable($full_path)) {
815 $this->_warning("File ". $full_path ." is not readable for ". get_current_user() ."\n");
819 $file_md5 = md5_file($full_path);
821 $this->_debug("Image [". $idx ."] ". $details['name'] ." Thumbnails:");
823 foreach($resolutions as $resolution) {
825 $thumb_path = $this->cfg->base_path ."/thumbs/". $resolution ."_". $file_md5;
827 /* if the thumbnail file doesn't exist, create it */
828 if(!file_exists($thumb_path)) {
830 $this->_debug(" ". $resolution ."px");
831 if(!$this->create_thumbnail($full_path, $thumb_path, $resolution))
835 /* if the file hasn't changed there is no need to regen the thumb */
836 elseif($file_md5 != $this->getMD5($idx) || $force) {
838 $this->_debug(" ". $resolution ."px");
839 if(!$this->create_thumbnail($full_path, $thumb_path, $resolution))
845 /* set the new/changed MD5 sum for the current photo */
847 $this->setMD5($idx, $file_md5);
854 public function getMD5($idx)
856 $result = $this->cfg_db->db_query("
859 WHERE img_idx='". $idx ."'
865 $img = $this->cfg_db->db_fetch_object($result);
866 return $img['img_md5'];
870 private function setMD5($idx, $md5)
872 $result = $this->cfg_db->db_exec("
873 REPLACE INTO images (img_idx, img_md5)
874 VALUES ('". $idx ."', '". $md5 ."')
879 public function setTagCondition($mode)
881 $_SESSION['tag_condition'] = $mode;
883 } // setTagCondition()
885 public function startTagSearch($searchfor)
887 $_SESSION['searchfor'] = $searchfor;
888 $_SESSION['selected_tags'] = Array();
890 foreach($this->avail_tags as $tag) {
891 if(preg_match('/'. $searchfor .'/i', $this->tags[$tag]))
892 array_push($_SESSION['selected_tags'], $tag);
895 } // startTagSearch()
897 private function rotateImage($img, $degrees)
899 if(function_exists("imagerotate"))
900 $img = imagerotate($img, $degrees, 0);
903 function imagerotate($src_img, $angle)
905 $src_x = imagesx($src_img);
906 $src_y = imagesy($src_img);
911 elseif ($src_x <= $src_y) {
915 elseif ($src_x >= $src_y) {
920 $rotate=imagecreatetruecolor($dest_x,$dest_y);
921 imagealphablending($rotate, false);
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, $dest_x - $y - 1, $x, $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, $y, $dest_y - $x - 1, $color);
944 for ($y = 0; $y < ($src_y); $y++) {
945 for ($x = 0; $x < ($src_x); $x++) {
946 $color = imagecolorat($src_img, $x, $y);
947 imagesetpixel($rotate, $dest_x - $x - 1, $dest_y - $y - 1, $color);
952 default: $rotate = $src_img;
959 $img = imagerotate($img, $degrees);
967 private function get_photo_tags($idx)
969 $result = $this->db->db_query("
972 INNER JOIN photo_tags pt
974 WHERE pt.photo_id='". $idx ."'
979 while($row = $this->db->db_fetch_object($result))
980 $tags[$row['id']] = $row['name'];
984 } // get_photo_tags()
986 public function showTextImage($txt, $color=000000, $space=4, $font=4, $w=300)
988 if (strlen($color) != 6)
991 $int = hexdec($color);
992 $h = imagefontheight($font);
993 $fw = imagefontwidth($font);
994 $txt = explode("\n", wordwrap($txt, ($w / $fw), "\n"));
995 $lines = count($txt);
996 $im = imagecreate($w, (($h * $lines) + ($lines * $space)));
997 $bg = imagecolorallocate($im, 255, 255, 255);
998 $color = imagecolorallocate($im, 0xFF & ($int >> 0x10), 0xFF & ($int >> 0x8), 0xFF & $int);
1001 foreach ($txt as $text) {
1002 $x = (($w - ($fw * strlen($text))) / 2);
1003 imagestring($im, $font, $x, $y, $text, $color);
1004 $y += ($h + $space);
1007 Header("Content-type: image/png");
1010 } // showTextImage()
1012 private function checkRequirements()
1014 if(!function_exists("imagecreatefromjpeg")) {
1015 print "PHP GD library extension is missing<br />\n";
1019 if(!function_exists("sqlite3_open")) {
1020 print "PHP SQLite3 library extension is missing<br />\n";
1024 /* Check for HTML_AJAX PEAR package, lent from Horde project */
1025 ini_set('track_errors', 1);
1026 @include_once 'HTML/AJAX/Server.php';
1027 if(isset($php_errormsg) && preg_match('/Failed opening.*for inclusion/i', $php_errormsg)) {
1028 print "PEAR HTML_AJAX package is missing<br />\n";
1031 @include_once 'Calendar/Calendar.php';
1032 if(isset($php_errormsg) && preg_match('/Failed opening.*for inclusion/i', $php_errormsg)) {
1033 print "PEAR Calendar package is missing<br />\n";
1036 ini_restore('track_errors');
1043 } // checkRequirements()
1045 private function _debug($text)
1047 if($this->fromcmd) {
1053 public function checkifImageSupported($mime)
1055 if(in_array($mime, Array("image/jpeg")))
1060 } // checkifImageSupported()
1062 public function _warning($text)
1064 print "<img src=\"resources/green_info.png\" alt=\"warning\" />\n";
1069 private function get_calendar()
1071 // require_once CALENDAR_ROOT.'Year.php';
1072 // require_once CALENDAR_ROOT.'Month.php';
1073 // require_once CALENDAR_ROOT.'Day.php';
1075 // $Year = new Calendar_Year();
1076 // $Month = new Calendar_Month();
1077 // $Day = new Calendar_Day();
1079 $output = "<select name=\"year\">\n";
1080 for($year = 1990; $year <= date("Y"); $year++) {
1081 $output.= "<option value=\"". $year ."\">". $year ."</option>\n";
1083 $output.= "</select>\n";
1085 $output.= "<select name=\"month\">\n";
1086 for($month = 1; $month <= 12; $month++) {
1087 $output.= "<option value=\"". $month ."\">". $month ."</option>\n";
1089 $output.= "</select>\n";
1091 $output.= "<select name=\"day\">\n";
1092 for($day = 1; $day <= 31; $day++) {
1093 $output.= "<option value=\"". $day ."\">". $day ."</option>\n";
1095 $output.= "</select>\n";