summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Unterkircher <unki@netshadow.at>2007-06-23 09:14:01 +0000
committerAndreas Unterkircher <unki@netshadow.at>2007-06-23 09:14:01 +0000
commitcb4b29076f41be249d2f4b54204085722ef6beff (patch)
treefc7e91d2c9b775cf440604e53fa109fd0511f2b5
parentfd0d0b81b545d0921697741ee149143c6aef17ce (diff)
new function to display text as images
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
-rw-r--r--phpfspot.class.php49
-rw-r--r--phpfspot_img.php15
2 files changed, 58 insertions, 6 deletions
diff --git a/phpfspot.class.php b/phpfspot.class.php
index 525b5c1..6800da2 100644
--- a/phpfspot.class.php
+++ b/phpfspot.class.php
@@ -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()
+
}
?>
diff --git a/phpfspot_img.php b/phpfspot_img.php
index 061f56d..69f579b 100644
--- a/phpfspot_img.php
+++ b/phpfspot_img.php
@@ -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);