new function to display text as images
authorAndreas Unterkircher <unki@netshadow.at>
Sat, 23 Jun 2007 09:14:01 +0000 (09:14 +0000)
committerAndreas Unterkircher <unki@netshadow.at>
Sat, 23 Jun 2007 09:14:01 +0000 (09:14 +0000)
more checks if orig & thumbnail are really their and readable

git-svn-id: file:///var/lib/svn/phpfspot/trunk@126 fa6a889d-dae6-447d-9e79-4ba9a3039384

phpfspot.class.php
phpfspot_img.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()
+
 }
 
 ?>
index 061f56d4f62ec1709aa9ba4f504b56c1f72ca33f..69f579bf20c04f32b16dc48228cf90ba3e8ce1d0 100644 (file)
@@ -21,9 +21,12 @@ class PHPFSPOT_IMG {
 
    public function show($idx, $width = 0)
    {
-      $this->parent->gen_thumb($idx);
-
       $details = $this->parent->get_photo_details($idx);
+   
+      if(!$details) {
+         $this->parent->showTextImage("The image you requested is unknown");
+         return;
+      }
 
       /* show original photo */
       if($width == 0) {
@@ -32,13 +35,17 @@ class PHPFSPOT_IMG {
       /* show thumbnail */
       else {
          $fullpath = $this->parent->cfg->base_path ."/thumbs/". $width ."_". $this->parent->getMD5($idx);
+         if(!file_exists($fullpath)) 
+            $this->parent->gen_thumb($idx, 0, 1);
       }
 
       if(!file_exists($fullpath)) {
-         $this->parent->gen_thumb($idx, 0, 1);
+         $this->parent->showTextImage("test1");
+         return;
       }
       if(!is_readable($fullpath)) {
-         die("File ". $fullpath ." is not readable. Check the permissions");
+         $this->parent->showTextImage("File ". $fullpath ." is not readable. Check the permissions");
+         return;
       }
 
       $tmp = getimagesize($fullpath);