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']);
68 $this->tmpl->show("export.tpl");
74 $this->tmpl->assign('content_page', 'welcome.tpl');
75 $this->tmpl->show("index.tpl");
80 private function get_tags()
83 $this->avail_tags = Array();
86 $result = $this->db->db_query("
89 ORDER BY sort_priority ASC
92 while($row = $this->db->db_fetch_object($result)) {
95 $tag_name = $row['name'];
97 /* check if config requests to ignore this tag */
98 if(in_array($row['name'], $this->cfg->hide_tags))
101 $this->tags[$tag_id] = $tag_name;
102 $this->avail_tags[$count] = $tag_id;
110 public function get_photo_details($idx)
112 $result = $this->db->db_query("
115 WHERE id='". $idx ."'
118 return $this->db->db_fetch_object($result);
120 } // get_photo_details
122 public function getPhotoName($idx)
124 if($details = $this->get_photo_details($idx)) {
126 $name = $details['name'];
128 if(strlen($name) > 15) {
129 $name = substr($name, 0, 10) ."...". substr($name, -10);
138 public function translate_path($path, $width = 0)
140 return str_replace($this->cfg->path_replace_from, $this->cfg->path_replace_to, $path);
144 public function showPhoto($photo)
146 $all_photos = $this->getPhotoSelection();
147 $count = count($all_photos);
149 for($i = 0; $i < $count; $i++) {
152 $next_img = $all_photos[$i];
156 if($all_photos[$i] == $photo) {
160 $previous_img = $all_photos[$i];
163 if($photo == $all_photos[$i]) {
168 $details = $this->get_photo_details($photo);
169 $orig_path = $this->translate_path($details['directory_path']) ."/". $details['name'];
170 $thumb_path = $this->cfg->base_path ."/thumbs/". $this->cfg->photo_width ."_". $this->getMD5($photo);
172 if(!file_exists($orig_path)) {
173 $this->_warning("Photo ". $orig_path ." does not exist!<br />\n");
176 if(!is_readable($orig_path)) {
177 $this->_warning("Photo ". $orig_path ." is not readable for user ". get_current_user() ."<br />\n");
180 /* If the thumbnail doesn't exist yet, try to create it */
181 if(!file_exists($thumb_path)) {
182 $this->gen_thumb($photo, true);
185 $meta = $this->get_meta_informations($orig_path);
187 /* If EXIF data are available, use them */
188 if(isset($meta['ExifImageWidth'])) {
189 $meta_res = $meta['ExifImageWidth'] ."x". $meta['ExifImageLength'];
191 $info = getimagesize($orig_path);
192 $meta_res = $info[0] ."x". $info[1];
195 $meta_date = isset($meta['FileDateTime']) ? strftime("%a %x %X", $meta['FileDateTime']) : "n/a";
196 $meta_make = isset($meta['Make']) ? $meta['Make'] ." ". $meta['Model'] : "n/a";
197 $meta_size = isset($meta['FileSize']) ? round($meta['FileSize']/1024, 1) ."kbyte" : "n/a";
199 if(file_exists($thumb_path)) {
201 $info = getimagesize($thumb_path);
203 $this->tmpl->assign('description', $details['description']);
204 $this->tmpl->assign('image_name', $details['name']);
206 $this->tmpl->assign('width', $info[0]);
207 $this->tmpl->assign('height', $info[1]);
208 $this->tmpl->assign('ExifMadeOn', $meta_date);
209 $this->tmpl->assign('ExifMadeWith', $meta_make);
210 $this->tmpl->assign('ExifOrigResolution', $meta_res);
211 $this->tmpl->assign('ExifFileSize', $meta_size);
213 $this->tmpl->assign('image_url', 'phpfspot_img.php?idx='. $photo ."&width=". $this->cfg->photo_width);
214 $this->tmpl->assign('image_url_full', 'phpfspot_img.php?idx='. $photo);
216 $this->tmpl->assign('tags', $this->get_photo_tags($photo));
217 $this->tmpl->assign('current', $current);
220 $this->_warning("Can't open file ". $thumb_path ."\n");
224 $this->tmpl->assign('previous_url', "javascript:showImage(". $previous_img .");");
225 $this->tmpl->assign('prev_img', $previous_img);
229 $this->tmpl->assign('next_url', "javascript:showImage(". $next_img .");");
230 $this->tmpl->assign('next_img', $next_img);
232 $this->tmpl->assign('mini_width', $this->cfg->mini_width);
234 $this->tmpl->show("single_photo.tpl");
238 public function getAvailableTags()
240 $result = $this->db->db_query("
241 SELECT tag_id as id, count(tag_id) as quantity
251 while($row = $this->db->db_fetch_object($result)) {
252 $tags[$row['id']] = $row['quantity'];
255 // change these font sizes if you will
256 $max_size = 125; // max font size in %
257 $min_size = 75; // min font size in %
259 // get the largest and smallest array values
260 $max_qty = max(array_values($tags));
261 $min_qty = min(array_values($tags));
263 // find the range of values
264 $spread = $max_qty - $min_qty;
265 if (0 == $spread) { // we don't want to divide by zero
269 // determine the font-size increment
270 // this is the increase per tag quantity (times used)
271 $step = ($max_size - $min_size)/($spread);
273 // loop through our tag array
274 foreach ($tags as $key => $value) {
276 if(isset($_SESSION['selected_tags']) && in_array($key, $_SESSION['selected_tags']))
279 // calculate CSS font-size
280 // find the $value in excess of $min_qty
281 // multiply by the font-size increment ($size)
282 // and add the $min_size set above
283 $size = $min_size + (($value - $min_qty) * $step);
284 // uncomment if you want sizes in whole %:
287 print "<a href=\"javascript:Tags('add', ". $key .");\" class=\"tag\" style=\"font-size: ". $size ."%;\">". $this->tags[$key] ."</a>, ";
291 } // getAvailableTags()
293 public function getSelectedTags()
296 foreach($this->avail_tags as $tag)
298 // return all selected tags
299 if(isset($_SESSION['selected_tags']) && in_array($tag, $_SESSION['selected_tags'])) {
300 $output.= "<a href=\"javascript:Tags('del', ". $tag .");\" class=\"tag\">". $this->tags[$tag] ."</a>, ";
304 $output = substr($output, 0, strlen($output)-2);
307 } // getSelectedTags()
309 public function addTag($tag)
311 if(!isset($_SESSION['selected_tags']))
312 $_SESSION['selected_tags'] = Array();
314 if(!in_array($tag, $_SESSION['selected_tags']))
315 array_push($_SESSION['selected_tags'], $tag);
319 public function delTag($tag)
321 if(isset($_SESSION['selected_tags'])) {
322 $key = array_search($tag, $_SESSION['selected_tags']);
323 unset($_SESSION['selected_tags'][$key]);
324 sort($_SESSION['selected_tags']);
329 public function resetTags()
331 unset($_SESSION['selected_tags']);
335 public function resetTagSearch()
337 unset($_SESSION['searchfor']);
339 } // resetTagSearch()
341 public function getPhotoSelection()
343 $tagged_photos = Array();
345 /* return a search result */
346 if(isset($_SESSION['searchfor']) && $_SESSION['searchfor'] != '') {
347 $result = $this->db->db_query("
348 SELECT DISTINCT photo_id
354 WHERE t.name LIKE '%". $_SESSION['searchfor'] ."%'
357 while($row = $this->db->db_fetch_object($result)) {
358 array_push($tagged_photos, $row['photo_id']);
360 return $tagged_photos;
363 /* return according the selected tags */
364 if(isset($_SESSION['selected_tags']) && !empty($_SESSION['selected_tags'])) {
366 foreach($_SESSION['selected_tags'] as $tag)
367 $selected.= $tag .",";
368 $selected = substr($selected, 0, strlen($selected)-1);
370 if($_SESSION['tag_condition'] == 'or') {
371 $result = $this->db->db_query("
372 SELECT DISTINCT photo_id
376 WHERE pt.tag_id IN (". $selected .")
380 elseif($_SESSION['tag_condition'] == 'and') {
382 if(count($_SESSION['selected_tags']) >= 32) {
383 print "A SQLite limit of 32 tables within a JOIN SELECT avoids to<br />\n";
384 print "evaluate your tag selection. Please remove some tags from your selection.\n";
388 /* Join together a table looking like
390 pt1.photo_id pt1.tag_id pt2.photo_id pt2.tag_id ...
392 so the query can quickly return all images matching the
393 selected tags in an AND condition
398 SELECT DISTINCT pt1.photo_id
402 for($i = 0; $i < count($_SESSION['selected_tags']); $i++) {
404 INNER JOIN photo_tags pt". ($i+2) ."
405 ON pt1.photo_id=pt". ($i+2) .".photo_id
408 $query_str.= "WHERE pt1.tag_id=". $_SESSION['selected_tags'][0];
409 for($i = 1; $i < count($_SESSION['selected_tags']); $i++) {
411 AND pt". ($i+1) .".tag_id=". $_SESSION['selected_tags'][$i] ."
414 $result = $this->db->db_query($query_str);
417 while($row = $this->db->db_fetch_object($result)) {
418 array_push($tagged_photos, $row['photo_id']);
420 return $tagged_photos;
423 /* return all available photos */
424 $result = $this->db->db_query("
425 SELECT DISTINCT photo_id
431 while($row = $this->db->db_fetch_object($result)) {
432 array_push($tagged_photos, $row['photo_id']);
434 return $tagged_photos;
436 } // getPhotoSelection()
438 public function showPhotoIndex()
440 $photos = $this->getPhotoSelection();
442 $count = count($photos);
444 if(isset($_SESSION['begin_with']) && $_SESSION['begin_with'] != "")
445 $anchor = $_SESSION['begin_with'];
447 if(!isset($this->cfg->rows_per_page) || $this->cfg->rows_per_page == 0) {
453 elseif($this->cfg->rows_per_page > 0) {
455 if(!$_SESSION['begin_with'] || $_SESSION['begin_with'] == 0)
459 $begin_with = $_SESSION['begin_with'];
461 // verify $begin_with - perhaps the thumbs-per-rows or
462 // rows-per-page variables have changed or the jump back
463 // from a photo wasn't exact - so calculate the real new
465 $multiplicator = $this->cfg->rows_per_page * $this->cfg->thumbs_per_row;
466 for($i = 0; $i <= $count; $i+=$multiplicator) {
467 if($begin_with >= $i && $begin_with < $i+$multiplicator) {
474 $end_with = $begin_with + ($this->cfg->rows_per_page * $this->cfg->thumbs_per_row);
480 $images[$rows] = Array();
481 $img_height[$rows] = Array();
482 $img_width[$rows] = Array();
483 $img_id[$rows] = Array();
484 $img_name[$rows] = Array();
486 for($i = $begin_with; $i < $end_with; $i++) {
488 $images[$rows][$cols] = $photos[$i];
489 $img_id[$rows][$cols] = $i;
490 $img_name[$rows][$cols] = $this->getPhotoName($photos[$i]);
492 $thumb_path = $this->cfg->base_path ."/thumbs/". $this->cfg->thumb_width ."_". $this->getMD5($photos[$i]);
494 if(file_exists($thumb_path)) {
495 $info = getimagesize($thumb_path);
496 $img_width[$rows][$cols] = $info[0];
497 $img_height[$rows][$cols] = $info[1];
500 if($cols == $this->cfg->thumbs_per_row-1) {
503 $images[$rows] = Array();
504 $img_width[$rows] = Array();
505 $img_height[$rows] = Array();
512 // +1 for for smarty's selection iteration
515 if(isset($_SESSION['searchfor']) && $_SESSION['searchfor'] != '')
516 $this->tmpl->assign('searchfor', $_SESSION['searchfor']);
518 /* do we have to display the page selector ? */
519 if($this->cfg->rows_per_page != 0) {
521 /* calculate the page switchers */
522 $previous_start = $begin_with - ($this->cfg->rows_per_page * $this->cfg->thumbs_per_row);
523 $next_start = $begin_with + ($this->cfg->rows_per_page * $this->cfg->thumbs_per_row);
526 $this->tmpl->assign("previous_url", "javascript:showPhotoIndex(". $previous_start .");");
527 if($end_with < $count)
528 $this->tmpl->assign("next_url", "javascript:showPhotoIndex(". $next_start .");");
530 $photo_per_page = $this->cfg->rows_per_page * $this->cfg->thumbs_per_row;
531 $last_page = ceil($count / $photo_per_page);
533 /* get the current selected page */
534 if($begin_with == 0) {
538 for($i = $begin_with; $i >= 0; $i-=$photo_per_page) {
543 for($i = 1; $i <= $last_page; $i++) {
545 if($current_page == $i)
546 $style = "style=\"font-size: 125%;\"";
547 elseif($current_page-1 == $i || $current_page+1 == $i)
548 $style = "style=\"font-size: 105%;\"";
549 elseif(($current_page-5 >= $i) && ($i != 1) ||
550 ($current_page+5 <= $i) && ($i != $last_page))
551 $style = "style=\"font-size: 75%;\"";
555 $select = "<a href=\"javascript:showPhotoIndex(". (($i*$photo_per_page)-$photo_per_page) .");\"";
558 $select.= ">". $i ."</a> ";
560 // until 9 pages we show the selector from 1-9
561 if($last_page <= 9) {
562 $page_select.= $select;
565 if($i == 1 /* first page */ ||
566 $i == $last_page /* last page */ ||
567 $i == $current_page /* current page */ ||
568 $i == ceil($last_page * 0.25) /* first quater */ ||
569 $i == ceil($last_page * 0.5) /* half */ ||
570 $i == ceil($last_page * 0.75) /* third quater */ ||
571 (in_array($i, array(1,2,3,4,5,6)) && $current_page <= 4) /* the first 6 */ ||
572 (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 */ ||
573 $i == $current_page-3 || $i == $current_page-2 || $i == $current_page-1 /* three before */ ||
574 $i == $current_page+3 || $i == $current_page+2 || $i == $current_page+1 /* three after */) {
576 $page_select.= $select;
585 /* only show the page selector if we have more then one page */
587 $this->tmpl->assign('page_selector', $page_select);
591 if($_SESSION['selected_tags'] != "") {
592 foreach($_SESSION['selected_tags'] as $tag)
593 $current_tags.= $tag .",";
594 $current_tags = substr($current_tags, 0, strlen($current_tags)-1);
597 $extern_link = "index.php?mode=showpi";
598 if($current_tags != "") {
599 $extern_link.= "&tags=". $current_tags;
602 $export_link = "index.php?mode=export";
604 $this->tmpl->assign('extern_link', $extern_link);
605 $this->tmpl->assign('export_link', $export_link);
606 $this->tmpl->assign('count', $count);
607 $this->tmpl->assign('width', $this->cfg->thumb_width);
608 $this->tmpl->assign('images', $images);
609 $this->tmpl->assign('img_width', $img_width);
610 $this->tmpl->assign('img_height', $img_height);
611 $this->tmpl->assign('img_id', $img_id);
612 $this->tmpl->assign('img_name', $img_name);
613 $this->tmpl->assign('rows', $rows);
614 $this->tmpl->assign('columns', $this->cfg->thumbs_per_row);
616 $this->tmpl->show("photo_index.tpl");
619 print "<script language=\"JavaScript\">self.location.hash = '#image". $anchor ."';</script>\n";
621 } // showPhotoIndex()
623 public function showBubbleDetails($photo, $direction)
625 if($direction == "up")
626 $direction = "bubbleimg_up";
628 $direction = "bubbleimg_down";
630 $details = $this->get_photo_details($photo);
631 $orig_path = $this->translate_path($details['directory_path']) ."/". $details['name'];
633 $image_url = "phpfspot_img.php?idx=". $photo ."&width=". $this->cfg->bubble_width;
635 $filesize = filesize($orig_path);
636 $filesize = rand($filesize/1024, 2);
638 if(!file_exists($orig_path)) {
639 $this->_warning("Photo ". $orig_path ." does not exist!<br />\n");
643 if(!is_readable($orig_path)) {
644 $this->_warning("Photo ". $orig_path ." is not readable for user ". get_current_user() ."<br />\n");
648 $img = getimagesize($orig_path);
650 $this->tmpl->assign('file_size', $filesize);
651 $this->tmpl->assign('width', $img[0]);
652 $this->tmpl->assign('height', $img[1]);
653 $this->tmpl->assign('file_name', $details['name']);
654 $this->tmpl->assign('image_id', $direction);
655 $this->tmpl->assign('image_url', $image_url);
656 $this->tmpl->show("bubble_details.tpl");
658 } // showBubbleDetails()
660 public function showCredits()
662 $this->tmpl->assign('version', $this->cfg->version);
663 $this->tmpl->assign('product', $this->cfg->product);
664 $this->tmpl->show("credits.tpl");
668 public function create_thumbnail($orig_image, $thumb_image, $width)
670 if(!file_exists($orig_image))
673 $details = getimagesize($orig_image);
675 /* check if original photo is a support image type */
676 if(!$this->checkifImageSupported($details['mime']))
679 $meta = $this->get_meta_informations($orig_image);
684 switch($meta['Orientation']) {
686 case 1: /* top, left */
687 $rotate = 0; $flip = false; break;
688 case 2: /* top, right */
689 $rotate = 0; $flip = true; break;
690 case 3: /* bottom, left */
691 $rotate = 180; $flip = false; break;
692 case 4: /* bottom, right */
693 $rotate = 180; $flip = true; break;
694 case 5: /* left side, top */
695 $rotate = 90; $flip = true; break;
696 case 6: /* right side, top */
697 $rotate = 90; $flip = false; break;
698 case 7: /* left side, bottom */
699 $rotate = 270; $flip = true; break;
700 case 8: /* right side, bottom */
701 $rotate = 270; $flip = false; break;
704 $src_img = @imagecreatefromjpeg($orig_image);
707 print "Can't load image from ". $orig_image ."\n";
711 /* grabs the height and width */
712 $cur_width = imagesx($src_img);
713 $cur_height = imagesy($src_img);
715 // If requested width is more then the actual image width,
716 // do not generate a thumbnail
718 if($width >= $cur_width) {
719 imagedestroy($src_img);
723 // If the image will be rotate because EXIF orientation said so
724 // 'virtually rotate' the image for further calculations
725 if($rotate == 90 || $rotate == 270) {
727 $cur_width = $cur_height;
731 /* calculates aspect ratio */
732 $aspect_ratio = $cur_height / $cur_width;
735 if($aspect_ratio < 1) {
737 $new_h = abs($new_w * $aspect_ratio);
739 /* 'virtually' rotate the image and calculate it's ratio */
740 $tmp_w = $cur_height;
742 /* now get the ratio from the 'rotated' image */
743 $tmp_ratio = $tmp_h/$tmp_w;
744 /* now calculate the new dimensions */
746 $tmp_h = abs($tmp_w * $tmp_ratio);
748 // now that we know, how high they photo should be, if it
749 // gets rotated, use this high to scale the image
751 $new_w = abs($new_h / $aspect_ratio);
753 // If the image will be rotate because EXIF orientation said so
754 // now 'virtually rotate' back the image for the image manipulation
755 if($rotate == 90 || $rotate == 270) {
762 /* creates new image of that size */
763 $dst_img = imagecreatetruecolor($new_w, $new_h);
765 imagefill($dst_img, 0, 0, ImageColorAllocate($dst_img, 255, 255, 255));
767 /* copies resized portion of original image into new image */
768 imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $new_w, $new_h, imagesx($src_img), imagesy($src_img));
770 /* needs the image to be flipped horizontal? */
774 for($x = 0; $x < $new_w; $x++) {
775 imagecopy($dst_img, $image, $x, 0, $w - $x - 1, 0, 1, $h);
780 $this->_debug("(ROTATE)");
781 $dst_img = $this->rotateImage($dst_img, $rotate);
784 /* write down new generated file */
785 $result = imagejpeg($dst_img, $thumb_image, 75);
788 imagedestroy($dst_img);
789 imagedestroy($src_img);
791 if($result === false) {
792 print "Can't write thumbnail ". $thumb_image ."\n";
798 } // create_thumbnail()
800 public function get_meta_informations($file)
802 return exif_read_data($file);
804 } // get_meta_informations()
806 public function check_config_table()
808 // if the config table doesn't exist yet, create it
809 if(!$this->cfg_db->db_check_table_exists("images")) {
810 $this->cfg_db->db_exec("
811 CREATE TABLE images (
812 img_idx int primary key,
818 } // check_config_table
821 * Generates a thumbnail from photo idx
823 * This function will generate JPEG thumbnails from provided F-Spot photo
826 * 1. Check if all thumbnail generations (width) are already in place and
828 * 2. Check if the md5sum of the original file has changed
829 * 3. Generate the thumbnails if needed
831 public function gen_thumb($idx = 0, $force = 0)
835 $resolutions = Array(
836 $this->cfg->thumb_width,
837 $this->cfg->bubble_width,
838 $this->cfg->photo_width,
839 $this->cfg->mini_width,
842 /* get details from F-Spot's database */
843 $details = $this->get_photo_details($idx);
845 /* calculate file MD5 sum */
846 $full_path = $this->translate_path($details['directory_path']) ."/". $details['name'];
848 if(!file_exists($full_path)) {
849 $this->_warning("File ". $full_path ." does not exist\n");
853 if(!is_readable($full_path)) {
854 $this->_warning("File ". $full_path ." is not readable for ". get_current_user() ."\n");
858 $file_md5 = md5_file($full_path);
860 $this->_debug("Image [". $idx ."] ". $details['name'] ." Thumbnails:");
862 foreach($resolutions as $resolution) {
864 $thumb_path = $this->cfg->base_path ."/thumbs/". $resolution ."_". $file_md5;
866 /* if the thumbnail file doesn't exist, create it */
867 if(!file_exists($thumb_path)) {
869 $this->_debug(" ". $resolution ."px");
870 if(!$this->create_thumbnail($full_path, $thumb_path, $resolution))
874 /* if the file hasn't changed there is no need to regen the thumb */
875 elseif($file_md5 != $this->getMD5($idx) || $force) {
877 $this->_debug(" ". $resolution ."px");
878 if(!$this->create_thumbnail($full_path, $thumb_path, $resolution))
884 /* set the new/changed MD5 sum for the current photo */
886 $this->setMD5($idx, $file_md5);
893 public function getMD5($idx)
895 $result = $this->cfg_db->db_query("
898 WHERE img_idx='". $idx ."'
904 $img = $this->cfg_db->db_fetch_object($result);
905 return $img['img_md5'];
909 private function setMD5($idx, $md5)
911 $result = $this->cfg_db->db_exec("
912 REPLACE INTO images (img_idx, img_md5)
913 VALUES ('". $idx ."', '". $md5 ."')
918 public function setTagCondition($mode)
920 $_SESSION['tag_condition'] = $mode;
922 } // setTagCondition()
924 public function startTagSearch($searchfor)
926 $_SESSION['searchfor'] = $searchfor;
927 $_SESSION['selected_tags'] = Array();
929 foreach($this->avail_tags as $tag) {
930 if(preg_match('/'. $searchfor .'/i', $this->tags[$tag]))
931 array_push($_SESSION['selected_tags'], $tag);
934 } // startTagSearch()
936 private function rotateImage($img, $degrees)
938 if(function_exists("imagerotate"))
939 $img = imagerotate($img, $degrees, 0);
942 function imagerotate($src_img, $angle)
944 $src_x = imagesx($src_img);
945 $src_y = imagesy($src_img);
950 elseif ($src_x <= $src_y) {
954 elseif ($src_x >= $src_y) {
959 $rotate=imagecreatetruecolor($dest_x,$dest_y);
960 imagealphablending($rotate, false);
965 for ($y = 0; $y < ($src_y); $y++) {
966 for ($x = 0; $x < ($src_x); $x++) {
967 $color = imagecolorat($src_img, $x, $y);
968 imagesetpixel($rotate, $dest_x - $y - 1, $x, $color);
974 for ($y = 0; $y < ($src_y); $y++) {
975 for ($x = 0; $x < ($src_x); $x++) {
976 $color = imagecolorat($src_img, $x, $y);
977 imagesetpixel($rotate, $y, $dest_y - $x - 1, $color);
983 for ($y = 0; $y < ($src_y); $y++) {
984 for ($x = 0; $x < ($src_x); $x++) {
985 $color = imagecolorat($src_img, $x, $y);
986 imagesetpixel($rotate, $dest_x - $x - 1, $dest_y - $y - 1, $color);
991 default: $rotate = $src_img;
998 $img = imagerotate($img, $degrees);
1006 private function get_photo_tags($idx)
1008 $result = $this->db->db_query("
1011 INNER JOIN photo_tags pt
1013 WHERE pt.photo_id='". $idx ."'
1018 while($row = $this->db->db_fetch_object($result))
1019 $tags[$row['id']] = $row['name'];
1023 } // get_photo_tags()
1025 public function showTextImage($txt, $color=000000, $space=4, $font=4, $w=300)
1027 if (strlen($color) != 6)
1030 $int = hexdec($color);
1031 $h = imagefontheight($font);
1032 $fw = imagefontwidth($font);
1033 $txt = explode("\n", wordwrap($txt, ($w / $fw), "\n"));
1034 $lines = count($txt);
1035 $im = imagecreate($w, (($h * $lines) + ($lines * $space)));
1036 $bg = imagecolorallocate($im, 255, 255, 255);
1037 $color = imagecolorallocate($im, 0xFF & ($int >> 0x10), 0xFF & ($int >> 0x8), 0xFF & $int);
1040 foreach ($txt as $text) {
1041 $x = (($w - ($fw * strlen($text))) / 2);
1042 imagestring($im, $font, $x, $y, $text, $color);
1043 $y += ($h + $space);
1046 Header("Content-type: image/png");
1049 } // showTextImage()
1051 private function checkRequirements()
1053 if(!function_exists("imagecreatefromjpeg")) {
1054 print "PHP GD library extension is missing<br />\n";
1058 if(!function_exists("sqlite3_open")) {
1059 print "PHP SQLite3 library extension is missing<br />\n";
1063 /* Check for HTML_AJAX PEAR package, lent from Horde project */
1064 ini_set('track_errors', 1);
1065 @include_once 'HTML/AJAX/Server.php';
1066 if(isset($php_errormsg) && preg_match('/Failed opening.*for inclusion/i', $php_errormsg)) {
1067 print "PEAR HTML_AJAX package is missing<br />\n";
1070 @include_once 'Calendar/Calendar.php';
1071 if(isset($php_errormsg) && preg_match('/Failed opening.*for inclusion/i', $php_errormsg)) {
1072 print "PEAR Calendar package is missing<br />\n";
1075 ini_restore('track_errors');
1082 } // checkRequirements()
1084 private function _debug($text)
1086 if($this->fromcmd) {
1092 public function checkifImageSupported($mime)
1094 if(in_array($mime, Array("image/jpeg")))
1099 } // checkifImageSupported()
1101 public function _warning($text)
1103 print "<img src=\"resources/green_info.png\" alt=\"warning\" />\n";
1108 private function get_calendar()
1110 // require_once CALENDAR_ROOT.'Year.php';
1111 // require_once CALENDAR_ROOT.'Month.php';
1112 // require_once CALENDAR_ROOT.'Day.php';
1114 // $Year = new Calendar_Year();
1115 // $Month = new Calendar_Month();
1116 // $Day = new Calendar_Day();
1118 $output = "<select name=\"year\">\n";
1119 for($year = 1990; $year <= date("Y"); $year++) {
1120 $output.= "<option value=\"". $year ."\">". $year ."</option>\n";
1122 $output.= "</select>\n";
1124 $output.= "<select name=\"month\">\n";
1125 for($month = 1; $month <= 12; $month++) {
1126 $output.= "<option value=\"". $month ."\">". $month ."</option>\n";
1128 $output.= "</select>\n";
1130 $output.= "<select name=\"day\">\n";
1131 for($day = 1; $day <= 31; $day++) {
1132 $output.= "<option value=\"". $day ."\">". $day ."</option>\n";
1134 $output.= "</select>\n";
1140 public function getExport($mode)
1142 $pictures = $this->getPhotoSelection();
1144 if(!isset($_SERVER['HTTPS'])) $protocol = "http";
1145 else $protocol = "https";
1147 $server_name = $_SERVER['SERVER_NAME'];
1149 foreach($pictures as $picture) {
1151 $orig_url = $protocol ."://". $server_name . $this->cfg->web_path ."phpfspot_img.php?idx=". $picture ."&width=". $this->cfg->photo_width;
1152 $thumb_url = $protocol ."://". $server_name . $this->cfg->web_path ."phpfspot_img.php?idx=". $picture ."&width=". $this->cfg->thumb_width;
1157 // <a href="%pictureurl%"><img src="%thumbnailurl%" ></a>
1158 print htmlspecialchars("<a href=\"". $orig_url ."\"><img src=\"". $thumb_url ."\" /></a>") ."<br />\n";
1162 // [%pictureurl% %thumbnailurl%]
1163 print htmlspecialchars("[$orig_url $thumb_url]") ."<br />\n";