changeset 16:5bfa7a3a6e7e

Move image text creation functionality to main module.
author ccr@tnsp.org
date Sat, 08 Jan 2011 23:33:12 +0200
parents 3a9798cc4631
children 4a3508ac4745
files index.php textimg.php
diffstat 2 files changed, 21 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/index.php	Sat Jan 08 23:27:32 2011 +0200
+++ b/index.php	Sat Jan 08 23:33:12 2011 +0200
@@ -4,6 +4,13 @@
 
 $tick = array_sum(explode(" ", microtime()));
 
+if (!extension_loaded('gd')) {
+   if (!dl('gd.so')) {
+       echo "Could not load extension GD!";
+       exit;
+   }
+}
+
 $dbModes = array(
   "min"  => array("Mineral", 0),
   "org"  => array("Organ", 1),
@@ -200,7 +207,20 @@
   foreach ($data2 as $key => $val) {
     $str = is_array($val) ? $val[0]." / ".$val[1] : $val;
     echo "  <th><img src=\"textimg.php?text=".urlencode($str)."\" alt=\"".htmlentities($str)."\" width=\"12\" height=\"80\"></th>\n";
-  }  
+
+    if (!file_exists($filename)) {
+      $image = imagecreate(12, 80);
+      $c_black = imagecolorallocate($image,   0,   0,   0);
+      $c_white = imagecolorallocate($image, 255, 255, 255);
+
+      imagefill($image, 0, 0, $c_black);
+      imagestringup($image, 2, -2, 78, $text, $c_white);
+
+      imagepng($image, $filename);
+      imagedestroy($image);
+    }
+  }
+  
   echo " </tr>\n";
 
   // Print the table itself
--- a/textimg.php	Sat Jan 08 23:27:32 2011 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,22 +0,0 @@
-<?
-if (!extension_loaded('gd')) {
-   if (!dl('gd.so')) {
-       echo "Could not load extension GD!";
-       exit;
-   }
-}
-
-$text = isset($_GET["text"]) ? $_GET["text"] : "-";
-
-$image = imagecreate(12, 80);
-$c_black = imagecolorallocate($image,   0,   0,   0);
-$c_white = imagecolorallocate($image, 255, 255, 255);
-
-imagefill($image, 0, 0, $c_black);
-imagestringup($image, 2, -2, 78, $text, $c_white);
-
-header("Content-Type: image/png");
-imagepng($image);
-
-imagedestroy($image);
-?>
\ No newline at end of file