new function to display text as images
[phpfspot.git] / phpfspot.class.php
index 525b5c1b0d4b8f8dc3d0858f53da994cc97909ef..6800da209794bd315979ec3f6926533491b4debb 100644 (file)
@@ -121,6 +121,14 @@ class PHPFSPOT {
       $orig_path = $this->translate_path($details['directory_path']) ."/". $details['name'];
       $thumb_path = $this->cfg->base_path ."/thumbs/". $this->cfg->photo_width ."_". $this->getMD5($photo);
 
+      if(!file_exists($orig_path)) {
+         print "Photo ". $orig_path ." does not exist!<br />\n";
+      }
+
+      if(!is_readable($orig_path)) {
+         print "Photo ". $orig_path ." is not readable for user ". get_current_user() ."<br />\n";
+      }
+
       /* If the thumbnail doesn't exist yet, try to create it */
       if(!file_exists($thumb_path)) {
          $this->gen_thumb($photo, 0, 1);
@@ -431,13 +439,24 @@ class PHPFSPOT {
          $direction = "bubbleimg_down";
 
       $details = $this->get_photo_details($photo);
+      $orig_path = $this->translate_path($details['directory_path'])  ."/". $details['name'];
 
       $image_url = "phpfspot_img.php?idx=". $photo ."&amp;width=". $this->cfg->bubble_width;
 
-      $filesize = filesize($this->translate_path($details['directory_path'])  ."/". $details['name']);
+      $filesize = filesize($orig_path);
       $filesize = rand($filesize/1024, 2);
 
-      $img = getimagesize($this->translate_path($details['directory_path'])  ."/". $details['name']);
+      if(!file_exists($orig_path)) {
+         print "Photo ". $orig_path ." does not exist!<br />\n";
+         return;
+      }
+      
+      if(!is_readable($orig_path)) {
+         print "Photo ". $orig_path ." is not readable for user ". get_current_user() ."<br />\n";
+         return;
+      }
+
+      $img = getimagesize($orig_path);
 
       $this->tmpl->assign('file_size', $filesize);
       $this->tmpl->assign('width', $img[0]);
@@ -755,6 +774,32 @@ class PHPFSPOT {
 
    } // get_photo_tags()
 
+   function showTextImage($txt, $color=000000, $space=4, $font=4, $w=300)
+   {
+      if (strlen($color) != 6) 
+         $color = 000000;
+
+      $int = hexdec($color);
+      $h = imagefontheight($font);
+      $fw = imagefontwidth($font);
+      $txt = explode("\n", wordwrap($txt, ($w / $fw), "\n"));
+      $lines = count($txt);
+      $im = imagecreate($w, (($h * $lines) + ($lines * $space)));
+      $bg = imagecolorallocate($im, 255, 255, 255);
+      $color = imagecolorallocate($im, 0xFF & ($int >> 0x10), 0xFF & ($int >> 0x8), 0xFF & $int);
+      $y = 0;
+
+      foreach ($txt as $text) {
+         $x = (($w - ($fw * strlen($text))) / 2);
+         imagestring($im, $font, $x, $y, $text, $color);
+         $y += ($h + $space);
+      }
+
+      Header("Content-type: image/png");
+      ImagePng($im);
+
+   } // showTextImage()
+
 }
 
 ?>