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 .");");
220 $this->tmpl->assign('prev_img', $previous_img);
224 $this->tmpl->assign('next_url', "javascript:showImage(". $next_img .");");
225 $this->tmpl->assign('next_img', $next_img);
227 $this->tmpl->assign('mini_width', $this->cfg->mini_width);
229 $this->tmpl->show("single_photo.tpl");
233 public function getAvailableTags()
235 $result = $this->db->db_query("
236 SELECT tag_id as id, count(tag_id) as quantity
246 while($row = $this->db->db_fetch_object($result)) {
247 $tags[$row['id']] = $row['quantity'];
250 // change these font sizes if you will
251 $max_size = 125; // max font size in %
252 $min_size = 75; // min font size in %
254 // get the largest and smallest array values
255 $max_qty = max(array_values($tags));
256 $min_qty = min(array_values($tags));
258 // find the range of values
259 $spread = $max_qty - $min_qty;
260 if (0 == $spread) { // we don't want to divide by zero
264 // determine the font-size increment
265 // this is the increase per tag quantity (times used)
266 $step = ($max_size - $min_size)/($spread);
268 // loop through our tag array
269 foreach ($tags as $key => $value) {
271 if(isset($_SESSION['selected_tags']) && in_array($key, $_SESSION['selected_tags']))
274 // calculate CSS font-size
275 // find the $value in excess of $min_qty
276 // multiply by the font-size increment ($size)
277 // and add the $min_size set above
278 $size = $min_size + (($value - $min_qty) * $step);
279 // uncomment if you want sizes in whole %:
282 print "<a href=\"javascript:Tags('add', ". $key .");\" class=\"tag\" style=\"font-size: ". $size ."%;\">". $this->tags[$key] ."</a>, ";
286 } // getAvailableTags()
288 public function getSelectedTags()
290 foreach($this->avail_tags as $tag)
292 // return all selected tags
293 if(isset($_SESSION['selected_tags']) && in_array($tag, $_SESSION['selected_tags'])) {
294 print "<a href=\"javascript:Tags('del', ". $tag .");\" class=\"tag\">". $this->tags[$tag] ."</a> ";
299 } // getSelectedTags()
301 public function addTag($tag)
303 if(!isset($_SESSION['selected_tags']))
304 $_SESSION['selected_tags'] = Array();
306 if(!in_array($tag, $_SESSION['selected_tags']))
307 array_push($_SESSION['selected_tags'], $tag);
311 public function delTag($tag)
313 if(isset($_SESSION['selected_tags'])) {
314 $key = array_search($tag, $_SESSION['selected_tags']);
315 unset($_SESSION['selected_tags'][$key]);
316 sort($_SESSION['selected_tags']);
321 public function resetTags()
323 unset($_SESSION['selected_tags']);
327 public function resetTagSearch()
329 unset($_SESSION['searchfor']);
331 } // resetTagSearch()
333 public function getPhotoSelection()
335 $tagged_photos = Array();
337 /* return a search result */
338 if(isset($_SESSION['searchfor']) && $_SESSION['searchfor'] != '') {
339 $result = $this->db->db_query("
340 SELECT DISTINCT photo_id
346 WHERE t.name LIKE '%". $_SESSION['searchfor'] ."%'
349 while($row = $this->db->db_fetch_object($result)) {
350 array_push($tagged_photos, $row['photo_id']);
352 return $tagged_photos;
355 /* return according the selected tags */
356 if(isset($_SESSION['selected_tags']) && !empty($_SESSION['selected_tags'])) {
358 foreach($_SESSION['selected_tags'] as $tag)
359 $selected.= $tag .",";
360 $selected = substr($selected, 0, strlen($selected)-1);
362 if($_SESSION['tag_condition'] == 'or') {
363 $result = $this->db->db_query("
364 SELECT DISTINCT photo_id
368 WHERE pt.tag_id IN (". $selected .")
372 elseif($_SESSION['tag_condition'] == 'and') {
374 /* Join together a table looking like
376 pt1.photo_id pt1.tag_id pt2.photo_id pt2.tag_id ...
378 so the query can quickly return all images matching the
379 selected tags in an AND condition
384 SELECT DISTINCT pt1.photo_id
388 for($i = 0; $i < count($_SESSION['selected_tags']); $i++) {
390 INNER JOIN photo_tags pt". ($i+2) ."
391 ON pt1.photo_id=pt". ($i+2) .".photo_id
394 $query_str.= "WHERE pt1.tag_id=". $_SESSION['selected_tags'][0];
395 for($i = 1; $i < count($_SESSION['selected_tags']); $i++) {
397 AND pt". ($i+1) .".tag_id=". $_SESSION['selected_tags'][$i] ."
400 $result = $this->db->db_query($query_str);
403 while($row = $this->db->db_fetch_object($result)) {
404 array_push($tagged_photos, $row['photo_id']);
406 return $tagged_photos;
409 /* return all available photos */
410 $result = $this->db->db_query("
411 SELECT DISTINCT photo_id
417 while($row = $this->db->db_fetch_object($result)) {
418 array_push($tagged_photos, $row['photo_id']);
420 return $tagged_photos;
422 } // getPhotoSelection()
424 public function showPhotoIndex()
426 $photos = $this->getPhotoSelection();
428 $count = count($photos);
430 if(isset($_SESSION['begin_with']) && $_SESSION['begin_with'] != "")
431 $anchor = $_SESSION['begin_with'];
433 if(!isset($this->cfg->rows_per_page) || $this->cfg->rows_per_page == 0) {
439 elseif($this->cfg->rows_per_page > 0) {
441 if(!$_SESSION['begin_with'] || $_SESSION['begin_with'] == 0)
445 $begin_with = $_SESSION['begin_with'];
447 // verify $begin_with - perhaps the thumbs-per-rows or
448 // rows-per-page variables have changed or the jump back
449 // from a photo wasn't exact - so calculate the real new
451 $multiplicator = $this->cfg->rows_per_page * $this->cfg->thumbs_per_row;
452 for($i = 0; $i <= $count; $i+=$multiplicator) {
453 if($begin_with >= $i && $begin_with < $i+$multiplicator) {
460 $end_with = $begin_with + ($this->cfg->rows_per_page * $this->cfg->thumbs_per_row);
466 $images[$rows] = Array();
467 $img_height[$rows] = Array();
468 $img_width[$rows] = Array();
469 $img_id[$rows] = Array();
470 $img_name[$rows] = Array();
472 for($i = $begin_with; $i < $end_with; $i++) {
474 $images[$rows][$cols] = $photos[$i];
475 $img_id[$rows][$cols] = $i;
476 $img_name[$rows][$cols] = $this->getPhotoName($photos[$i]);
478 $thumb_path = $this->cfg->base_path ."/thumbs/". $this->cfg->thumb_width ."_". $this->getMD5($photos[$i]);
480 if(file_exists($thumb_path)) {
481 $info = getimagesize($thumb_path);
482 $img_width[$rows][$cols] = $info[0];
483 $img_height[$rows][$cols] = $info[1];
486 if($cols == $this->cfg->thumbs_per_row-1) {
489 $images[$rows] = Array();
490 $img_width[$rows] = Array();
491 $img_height[$rows] = Array();
498 // +1 for for smarty's selection iteration
501 if(isset($_SESSION['searchfor']) && $_SESSION['searchfor'] != '')
502 $this->tmpl->assign('searchfor', $_SESSION['searchfor']);
504 /* do we have to display the page selector ? */
505 if($this->cfg->rows_per_page != 0) {
507 /* calculate the page switchers */
508 $previous_start = $begin_with - ($this->cfg->rows_per_page * $this->cfg->thumbs_per_row);
509 $next_start = $begin_with + ($this->cfg->rows_per_page * $this->cfg->thumbs_per_row);
512 $this->tmpl->assign("previous_url", "javascript:showPhotoIndex(". $previous_start .");");
513 if($end_with < $count)
514 $this->tmpl->assign("next_url", "javascript:showPhotoIndex(". $next_start .");");
516 $photo_per_page = $this->cfg->rows_per_page * $this->cfg->thumbs_per_row;
517 $last_page = ceil($count / $photo_per_page);
519 /* get the current selected page */
520 if($begin_with == 0) {
524 for($i = $begin_with; $i >= 0; $i-=$photo_per_page) {
529 for($i = 1; $i <= $last_page; $i++) {
531 if($current_page == $i)
532 $style = "style=\"font-size: 125%;\"";
533 elseif($current_page-1 == $i || $current_page+1 == $i)
534 $style = "style=\"font-size: 105%;\"";
535 elseif(($current_page-5 >= $i) && ($i != 1) ||
536 ($current_page+5 <= $i) && ($i != $last_page))
537 $style = "style=\"font-size: 75%;\"";
541 $select = "<a href=\"javascript:showPhotoIndex(". (($i*$photo_per_page)-$photo_per_page) .");\"";
544 $select.= ">". $i ."</a> ";
546 // until 9 pages we show the selector from 1-9
547 if($last_page <= 9) {
548 $page_select.= $select;
551 if($i == 1 /* first page */ ||
552 $i == $last_page /* last page */ ||
553 $i == $current_page /* current page */ ||
554 $i == ceil($last_page * 0.25) /* first quater */ ||
555 $i == ceil($last_page * 0.5) /* half */ ||
556 $i == ceil($last_page * 0.75) /* third quater */ ||
557 (in_array($i, array(1,2,3,4,5,6)) && $current_page <= 4) /* the first 6 */ ||
558 (in_array($i, array($last_page, $last_page-1, $last_page-2, $last_page-3, $last_page-4, $last_page-5)) && $current_page >= $last_page-4) /* the last 6 */ ||
559 $i == $current_page-3 || $i == $current_page-2 || $i == $current_page-1 /* three before */ ||
560 $i == $current_page+3 || $i == $current_page+2 || $i == $current_page+1 /* three after */) {
562 $page_select.= $select;
571 /* only show the page selector if we have more then one page */
573 $this->tmpl->assign('page_selector', $page_select);
577 if($_SESSION['selected_tags'] != "") {
578 foreach($_SESSION['selected_tags'] as $tag)
579 $current_tags.= $tag .",";
580 $current_tags = substr($current_tags, 0, strlen($current_tags)-1);
583 $extern_link = "http://". $_SERVER['SERVER_NAME'] ."/index.php?mode=showpi";
584 if($current_tags != "") {
585 $extern_link.= "&tags=". $current_tags;
588 $this->tmpl->assign('extern_link', $extern_link);
589 $this->tmpl->assign('count', $count);
590 $this->tmpl->assign('width', $this->cfg->thumb_width);
591 $this->tmpl->assign('images', $images);
592 $this->tmpl->assign('img_width', $img_width);
593 $this->tmpl->assign('img_height', $img_height);
594 $this->tmpl->assign('img_id', $img_id);
595 $this->tmpl->assign('img_name', $img_name);
596 $this->tmpl->assign('rows', $rows);
597 $this->tmpl->assign('columns', $this->cfg->thumbs_per_row);
599 $this->tmpl->show("photo_index.tpl");
602 print "<script language=\"JavaScript\">self.location.hash = '#image". $anchor ."';</script>\n";
604 } // showPhotoIndex()
606 public function showBubbleDetails($photo, $direction)
608 if($direction == "up")
609 $direction = "bubbleimg_up";
611 $direction = "bubbleimg_down";
613 $details = $this->get_photo_details($photo);
614 $orig_path = $this->translate_path($details['directory_path']) ."/". $details['name'];
616 $image_url = "phpfspot_img.php?idx=". $photo ."&width=". $this->cfg->bubble_width;
618 $filesize = filesize($orig_path);
619 $filesize = rand($filesize/1024, 2);
621 if(!file_exists($orig_path)) {
622 $this->_warning("Photo ". $orig_path ." does not exist!<br />\n");
626 if(!is_readable($orig_path)) {
627 $this->_warning("Photo ". $orig_path ." is not readable for user ". get_current_user() ."<br />\n");
631 $img = getimagesize($orig_path);
633 $this->tmpl->assign('file_size', $filesize);
634 $this->tmpl->assign('width', $img[0]);
635 $this->tmpl->assign('height', $img[1]);
636 $this->tmpl->assign('file_name', $details['name']);
637 $this->tmpl->assign('image_id', $direction);
638 $this->tmpl->assign('image_url', $image_url);
639 $this->tmpl->show("bubble_details.tpl");
641 } // showBubbleDetails()
643 public function showCredits()
645 $this->tmpl->assign('version', $this->cfg->version);
646 $this->tmpl->assign('product', $this->cfg->product);
647 $this->tmpl->show("credits.tpl");
651 public function create_thumbnail($orig_image, $thumb_image, $width)
653 if(!file_exists($orig_image))
656 $details = getimagesize($orig_image);
658 /* check if original photo is a support image type */
659 if(!$this->checkifImageSupported($details['mime']))
662 $meta = $this->get_meta_informations($orig_image);
667 switch($meta['Orientation']) {
669 case 1: /* top, left */
670 $rotate = 0; $flip = false; break;
671 case 2: /* top, right */
672 $rotate = 0; $flip = true; break;
673 case 3: /* bottom, left */
674 $rotate = 180; $flip = false; break;
675 case 4: /* bottom, right */
676 $rotate = 180; $flip = true; break;
677 case 5: /* left side, top */
678 $rotate = 90; $flip = true; break;
679 case 6: /* right side, top */
680 $rotate = 90; $flip = false; break;
681 case 7: /* left side, bottom */
682 $rotate = 270; $flip = true; break;
683 case 8: /* right side, bottom */
684 $rotate = 270; $flip = false; break;
687 $src_img = @imagecreatefromjpeg($orig_image);
690 print "Can't load image from ". $orig_image ."\n";
694 /* grabs the height and width */
695 $cur_width = imagesx($src_img);
696 $cur_height = imagesy($src_img);
698 // If requested width is more then the actual image width,
699 // do not generate a thumbnail
701 if($width >= $cur_width) {
702 imagedestroy($src_img);
706 // If the image will be rotate because EXIF orientation said so
707 // 'virtually rotate' the image for further calculations
708 if($rotate == 90 || $rotate == 270) {
710 $cur_width = $cur_height;
714 /* calculates aspect ratio */
715 $aspect_ratio = $cur_height / $cur_width;
718 if($aspect_ratio < 1) {
720 $new_h = abs($new_w * $aspect_ratio);
722 /* 'virtually' rotate the image and calculate it's ratio */
723 $tmp_w = $cur_height;
725 /* now get the ratio from the 'rotated' image */
726 $tmp_ratio = $tmp_h/$tmp_w;
727 /* now calculate the new dimensions */
729 $tmp_h = abs($tmp_w * $tmp_ratio);
731 // now that we know, how high they photo should be, if it
732 // gets rotated, use this high to scale the image
734 $new_w = abs($new_h / $aspect_ratio);
736 // If the image will be rotate because EXIF orientation said so
737 // now 'virtually rotate' back the image for the image manipulation
738 if($rotate == 90 || $rotate == 270) {
745 /* creates new image of that size */
746 $dst_img = imagecreatetruecolor($new_w, $new_h);
748 imagefill($dst_img, 0, 0, ImageColorAllocate($dst_img, 255, 255, 255));
750 /* copies resized portion of original image into new image */
751 imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $new_w, $new_h, imagesx($src_img), imagesy($src_img));
753 /* needs the image to be flipped horizontal? */
757 for($x = 0; $x < $new_w; $x++) {
758 imagecopy($dst_img, $image, $x, 0, $w - $x - 1, 0, 1, $h);
763 $this->_debug("(ROTATE)");
764 $dst_img = $this->rotateImage($dst_img, $rotate);
767 /* write down new generated file */
768 $result = imagejpeg($dst_img, $thumb_image, 75);
771 imagedestroy($dst_img);
772 imagedestroy($src_img);
774 if($result === false) {
775 print "Can't write thumbnail ". $thumb_image ."\n";
781 } // create_thumbnail()
783 public function get_meta_informations($file)
785 return exif_read_data($file);
787 } // get_meta_informations()
789 public function check_config_table()
791 // if the config table doesn't exist yet, create it
792 if(!$this->cfg_db->db_check_table_exists("images")) {
793 $this->cfg_db->db_exec("
794 CREATE TABLE images (
795 img_idx int primary key,
801 } // check_config_table
804 * Generates a thumbnail from photo idx
806 * This function will generate JPEG thumbnails from provided F-Spot photo
809 * 1. Check if all thumbnail generations (width) are already in place and
811 * 2. Check if the md5sum of the original file has changed
812 * 3. Generate the thumbnails if needed
814 public function gen_thumb($idx = 0, $force = 0)
818 $resolutions = Array(
819 $this->cfg->thumb_width,
820 $this->cfg->bubble_width,
821 $this->cfg->photo_width,
822 $this->cfg->mini_width,
825 /* get details from F-Spot's database */
826 $details = $this->get_photo_details($idx);
828 /* calculate file MD5 sum */
829 $full_path = $this->translate_path($details['directory_path']) ."/". $details['name'];
831 if(!file_exists($full_path)) {
832 $this->_warning("File ". $full_path ." does not exist\n");
836 if(!is_readable($full_path)) {
837 $this->_warning("File ". $full_path ." is not readable for ". get_current_user() ."\n");
841 $file_md5 = md5_file($full_path);
843 $this->_debug("Image [". $idx ."] ". $details['name'] ." Thumbnails:");
845 foreach($resolutions as $resolution) {
847 $thumb_path = $this->cfg->base_path ."/thumbs/". $resolution ."_". $file_md5;
849 /* if the thumbnail file doesn't exist, create it */
850 if(!file_exists($thumb_path)) {
852 $this->_debug(" ". $resolution ."px");
853 if(!$this->create_thumbnail($full_path, $thumb_path, $resolution))
857 /* if the file hasn't changed there is no need to regen the thumb */
858 elseif($file_md5 != $this->getMD5($idx) || $force) {
860 $this->_debug(" ". $resolution ."px");
861 if(!$this->create_thumbnail($full_path, $thumb_path, $resolution))
867 /* set the new/changed MD5 sum for the current photo */
869 $this->setMD5($idx, $file_md5);
876 public function getMD5($idx)
878 $result = $this->cfg_db->db_query("
881 WHERE img_idx='". $idx ."'
887 $img = $this->cfg_db->db_fetch_object($result);
888 return $img['img_md5'];
892 private function setMD5($idx, $md5)
894 $result = $this->cfg_db->db_exec("
895 REPLACE INTO images (img_idx, img_md5)
896 VALUES ('". $idx ."', '". $md5 ."')
901 public function setTagCondition($mode)
903 $_SESSION['tag_condition'] = $mode;
905 } // setTagCondition()
907 public function startTagSearch($searchfor)
909 $_SESSION['searchfor'] = $searchfor;
910 $_SESSION['selected_tags'] = Array();
912 foreach($this->avail_tags as $tag) {
913 if(preg_match('/'. $searchfor .'/i', $this->tags[$tag]))
914 array_push($_SESSION['selected_tags'], $tag);
917 } // startTagSearch()
919 private function rotateImage($img, $degrees)
921 if(function_exists("imagerotate"))
922 $img = imagerotate($img, $degrees, 0);
925 function imagerotate($src_img, $angle)
927 $src_x = imagesx($src_img);
928 $src_y = imagesy($src_img);
933 elseif ($src_x <= $src_y) {
937 elseif ($src_x >= $src_y) {
942 $rotate=imagecreatetruecolor($dest_x,$dest_y);
943 imagealphablending($rotate, false);
948 for ($y = 0; $y < ($src_y); $y++) {
949 for ($x = 0; $x < ($src_x); $x++) {
950 $color = imagecolorat($src_img, $x, $y);
951 imagesetpixel($rotate, $dest_x - $y - 1, $x, $color);
957 for ($y = 0; $y < ($src_y); $y++) {
958 for ($x = 0; $x < ($src_x); $x++) {
959 $color = imagecolorat($src_img, $x, $y);
960 imagesetpixel($rotate, $y, $dest_y - $x - 1, $color);
966 for ($y = 0; $y < ($src_y); $y++) {
967 for ($x = 0; $x < ($src_x); $x++) {
968 $color = imagecolorat($src_img, $x, $y);
969 imagesetpixel($rotate, $dest_x - $x - 1, $dest_y - $y - 1, $color);
974 default: $rotate = $src_img;
981 $img = imagerotate($img, $degrees);
989 private function get_photo_tags($idx)
991 $result = $this->db->db_query("
994 INNER JOIN photo_tags pt
996 WHERE pt.photo_id='". $idx ."'
1001 while($row = $this->db->db_fetch_object($result))
1002 $tags[$row['id']] = $row['name'];
1006 } // get_photo_tags()
1008 public function showTextImage($txt, $color=000000, $space=4, $font=4, $w=300)
1010 if (strlen($color) != 6)
1013 $int = hexdec($color);
1014 $h = imagefontheight($font);
1015 $fw = imagefontwidth($font);
1016 $txt = explode("\n", wordwrap($txt, ($w / $fw), "\n"));
1017 $lines = count($txt);
1018 $im = imagecreate($w, (($h * $lines) + ($lines * $space)));
1019 $bg = imagecolorallocate($im, 255, 255, 255);
1020 $color = imagecolorallocate($im, 0xFF & ($int >> 0x10), 0xFF & ($int >> 0x8), 0xFF & $int);
1023 foreach ($txt as $text) {
1024 $x = (($w - ($fw * strlen($text))) / 2);
1025 imagestring($im, $font, $x, $y, $text, $color);
1026 $y += ($h + $space);
1029 Header("Content-type: image/png");
1032 } // showTextImage()
1034 private function checkRequirements()
1036 if(!function_exists("imagecreatefromjpeg")) {
1037 print "PHP GD library extension is missing<br />\n";
1041 if(!function_exists("sqlite3_open")) {
1042 print "PHP SQLite3 library extension is missing<br />\n";
1046 /* Check for HTML_AJAX PEAR package, lent from Horde project */
1047 ini_set('track_errors', 1);
1048 @include_once 'HTML/AJAX/Server.php';
1049 if(isset($php_errormsg) && preg_match('/Failed opening.*for inclusion/i', $php_errormsg)) {
1050 print "PEAR HTML_AJAX package is missing<br />\n";
1053 @include_once 'Calendar/Calendar.php';
1054 if(isset($php_errormsg) && preg_match('/Failed opening.*for inclusion/i', $php_errormsg)) {
1055 print "PEAR Calendar package is missing<br />\n";
1058 ini_restore('track_errors');
1065 } // checkRequirements()
1067 private function _debug($text)
1069 if($this->fromcmd) {
1075 public function checkifImageSupported($mime)
1077 if(in_array($mime, Array("image/jpeg")))
1082 } // checkifImageSupported()
1084 public function _warning($text)
1086 print "<img src=\"resources/green_info.png\" alt=\"warning\" />\n";
1091 private function get_calendar()
1093 // require_once CALENDAR_ROOT.'Year.php';
1094 // require_once CALENDAR_ROOT.'Month.php';
1095 // require_once CALENDAR_ROOT.'Day.php';
1097 // $Year = new Calendar_Year();
1098 // $Month = new Calendar_Month();
1099 // $Day = new Calendar_Day();
1101 $output = "<select name=\"year\">\n";
1102 for($year = 1990; $year <= date("Y"); $year++) {
1103 $output.= "<option value=\"". $year ."\">". $year ."</option>\n";
1105 $output.= "</select>\n";
1107 $output.= "<select name=\"month\">\n";
1108 for($month = 1; $month <= 12; $month++) {
1109 $output.= "<option value=\"". $month ."\">". $month ."</option>\n";
1111 $output.= "</select>\n";
1113 $output.= "<select name=\"day\">\n";
1114 for($day = 1; $day <= 31; $day++) {
1115 $output.= "<option value=\"". $day ."\">". $day ."</option>\n";
1117 $output.= "</select>\n";