diff -urp HEAD/captcha.inc 6.x-1.x-dev/captcha.inc
--- HEAD/captcha.inc	2008-05-26 10:31:23.000000000 +1000
+++ 6.x-1.x-dev/captcha.inc	2008-05-26 12:13:10.000000000 +1000
@@ -1,13 +1,14 @@
 <?php
 // $Id: captcha.inc,v 1.2 2007/01/31 09:46:06 heine Exp $
+
 /**
  * @file
  * Provides textimage captcha functions
  */
 
 /**
-* Captcha settings form.
-*/
+ * Captcha settings form.
+ */
 function textimage_captcha_settings_form() {
 
   $fonts_path = variable_get("textimage_captcha_fonts_path", "");
@@ -40,7 +41,7 @@ function textimage_captcha_settings_form
   $form['fonts']['textimage_captcha_font_size'] = array(
     '#type' => 'textfield',
     '#title' => t('Font Size'),
-    '#default_value' =>  variable_get('textimage_captcha_font_size',24),
+    '#default_value' =>  variable_get('textimage_captcha_font_size', 24),
     '#size' => 5,
     '#maxlength' => 2,
     '#description' => t('Font size of Captcha text (in pixels).'),
@@ -50,7 +51,7 @@ function textimage_captcha_settings_form
   $form['fonts']['textimage_captcha_char_spacing_max'] = array(
     '#type' => 'textfield',
     '#title' => t('Character Spacing'),
-    '#default_value' =>  variable_get('textimage_captcha_char_spacing_max',10),
+    '#default_value' =>  variable_get('textimage_captcha_char_spacing_max', 10),
     '#size' => 5,
     '#maxlength' => 4,
     '#description' => t('Sets the kerning between letters in Captcha. Higher numbers indicate more spacing.'),
@@ -60,7 +61,7 @@ function textimage_captcha_settings_form
   $form['fonts']['textimage_captcha_char_jiggle_amount'] = array(
     '#type' => 'textfield',
     '#title' => t('Character Jiggle'),
-    '#default_value' =>  variable_get('textimage_captcha_char_jiggle_amount',5),
+    '#default_value' =>  variable_get('textimage_captcha_char_jiggle_amount', 5),
     '#size' => 5,
     '#maxlength' => 2,
     '#description' => t('Sets the amount of up and down movement in the Captcha letters. Higher numbers indicate more jiggling.'),
@@ -70,7 +71,7 @@ function textimage_captcha_settings_form
   $form['fonts']['textimage_captcha_char_rotate_amount'] = array(
     '#type' => 'textfield',
     '#title' => t('Character Rotation'),
-    '#default_value' =>  variable_get('textimage_captcha_char_rotate_amount',5),
+    '#default_value' =>  variable_get('textimage_captcha_char_rotate_amount', 5),
     '#size' => 5,
     '#maxlength' => 2,
     '#description' => t('Sets the amount of rotation in the Captcha letters (in degrees, only works with non-default fonts).'),
@@ -80,7 +81,7 @@ function textimage_captcha_settings_form
   $form['fonts']['textimage_captcha_char_size_amount'] = array(
     '#type' => 'textfield',
     '#title' => t('Character Size Adjustment'),
-    '#default_value' =>  variable_get('textimage_captcha_char_size_amount',2),
+    '#default_value' =>  variable_get('textimage_captcha_char_size_amount', 2),
     '#size' => 5,
     '#maxlength' => 2,
     '#description' => t('Sets the amount of variation in size between the different letters in the Captcha (in pixels).'),
@@ -90,7 +91,7 @@ function textimage_captcha_settings_form
   $form['fonts']['textimage_captcha_use_only_upper'] = array(
     '#type' => 'checkbox',
     '#title' => t('Use only Uppercase'),
-    '#default_value' => variable_get('textimage_captcha_use_only_upper',0)
+    '#default_value' => variable_get('textimage_captcha_use_only_upper', 0)
   );
 
   //Image settings
@@ -110,7 +111,7 @@ function textimage_captcha_settings_form
   $form['images']['textimage_captcha_image_noise'] = array(
     '#type' => 'textfield',
     '#title' => t('Image Noise (pixels)'),
-    '#default_value' =>  variable_get('textimage_captcha_image_noise',4),
+    '#default_value' =>  variable_get('textimage_captcha_image_noise', 4),
     '#size' => 5,
     '#maxlength' => 4,
     '#description' => t('Sets the amount of noise (random pixels) in the Captcha image. Higher numbers indicate more noise.'),
@@ -120,7 +121,7 @@ function textimage_captcha_settings_form
   $form['images']['textimage_captcha_image_lines'] = array(
     '#type' => 'textfield',
     '#title' => t('Image Noise (lines)'),
-    '#default_value' =>  variable_get('textimage_captcha_image_lines',4),
+    '#default_value' =>  variable_get('textimage_captcha_image_lines', 4),
     '#size' => 5,
     '#maxlength' => 4,
     '#description' => t('Sets the amount of noise (random lines) in the Captcha image. Higher numbers indicate more noise.'),
@@ -130,7 +131,7 @@ function textimage_captcha_settings_form
   $form['images']['textimage_captcha_image_margin'] = array(
     '#type' => 'textfield',
     '#title' => t('Image Margin'),
-    '#default_value' =>  variable_get('textimage_captcha_image_margin',10),
+    '#default_value' =>  variable_get('textimage_captcha_image_margin', 10),
     '#size' => 5,
     '#maxlength' => 4,
     '#description' => t('Set a distance between the Captcha letters and the edges of the image.'),
@@ -143,13 +144,13 @@ function textimage_captcha_settings_form
     '#collapsible' => TRUE, '#collapsed' => FALSE
   );
   if (isset($fonts_path)) {
-    $imagefontinfo .= t('Number of captcha fonts found: ').count(_textimage_font_list($fonts_path));
+    $imagefontinfo .= t('Number of captcha fonts found: ') . count(_textimage_font_list($fonts_path));
   }
   if (isset($images_path)) {
-    $imagefontinfo .= '<br />'.t('Number of captcha background images found: ').count(_textimage_image_list($images_path));
+    $imagefontinfo .= '<br />'. t('Number of captcha background images found: ') . count(_textimage_image_list($images_path));
   }
 
-  $form['info']['captcha_info'] = array (
+  $form['info']['captcha_info'] = array(
    '#type' => 'item',
    '#value' => $imagefontinfo,
   );
@@ -157,14 +158,14 @@ function textimage_captcha_settings_form
   return system_settings_form($form);
 }
 
-function textimage_captcha_settings_form_validate($form_id, $form_values) {
-  textimage_settings_form_validate($form_id, $form_values);
+function textimage_captcha_settings_form_validate($form, &$form_state) {
+  textimage_settings_form_validate($form, &$form_state);
 }
 
 
 /**
-* Prints an image containing a textimage code.
-*/
+ * Prints an image containing a textimage code.
+ */
 function _textimage_captcha_image() {
   //if we don't have GD2 functions, we can't generate the image
   if (!function_exists('imagecreatetruecolor')) return;
@@ -185,49 +186,49 @@ function _textimage_captcha_image() {
   $images = _textimage_image_list(variable_get("textimage_captcha_images_path", ""));
 
   // Randomization amounts:
-  $charSpacingMax   = variable_get('textimage_captcha_char_spacing_max',10);   // Letter spacing max (pixels)
-  $charSpacingMin   = max($charSpacingMax*.5,0);                     // Letter spacing minimum (pixels)
-  $charJiggleAmount = variable_get('textimage_captcha_char_jiggle_amount',5);  // Up and down randomization (pixels)
-  $charRotateAmount = variable_get('textimage_captcha_char_rotate_amount',5);  // Character rotation amount (degrees)
-  $charSizeAmount   = variable_get('textimage_captcha_char_size_amount',2);    // Character size amount (pixels)
+  $char_spacing_max   = variable_get('textimage_captcha_char_spacing_max', 10);   // Letter spacing max (pixels)
+  $char_spacing_min   = max($char_spacing_max* . 5, 0);                     // Letter spacing minimum (pixels)
+  $char_jiggle_amount = variable_get('textimage_captcha_char_jiggle_amount', 5);  // Up and down randomization (pixels)
+  $char_rotate_amount = variable_get('textimage_captcha_char_rotate_amount', 5);  // Character rotation amount (degrees)
+  $char_size_amount   = variable_get('textimage_captcha_char_size_amount', 2);    // Character size amount (pixels)
 
   // Static amounts:
-  $charInitialSize   = variable_get('textimage_captcha_font_size',24);      // Initial Font
-  $imageNoise        = variable_get('textimage_captcha_image_noise',4);    // Amount of noise added to image
-  $imageLines        = variable_get('textimage_captcha_image_lines',4);    // Amount of noise added to image
-  $imageMargin       = variable_get('textimage_captcha_image_margin',10);    // Margin around image (pixels)
+  $char_initial_size  = variable_get('textimage_captcha_font_size', 24);      // Initial Font
+  $image_noise        = variable_get('textimage_captcha_image_noise', 4);    // Amount of noise added to image
+  $image_lines        = variable_get('textimage_captcha_image_lines', 4);    // Amount of noise added to image
+  $image_margin       = variable_get('textimage_captcha_image_margin', // Margin around image (pixels)
 
-  $imageWidth = 0;
+  $image_width = 0;
 
   // write text using a truetype font
   if (function_exists(imagettftext) && count($fonts) > 0) {
 
     // Initialize variables for the loop
-    $characterDetails = array(); // contains the final info about each character
+    $character_details = array(); // contains the final info about each character
 
     // Build a list of character settings for the captcha string
     for ($i=0;$i<drupal_strlen($string);$i++) {
       // Select our character
-      $char = drupal_substr($string,$i,1);
+      $char = drupal_substr($string, $i, 1);
 
       // Define angle, size, and font of the character
-      $charAngle = rand(-$charRotateAmount,$charRotateAmount);
-      $charSize  = $charInitialSize + rand(-$charSizeAmount,$charSizeAmount);
-      $font = variable_get("textimage_captcha_fonts_path", "") . '/' . $fonts[rand(0,count($fonts)-1)];
+      $char_angle = rand(-$char_rotate_amount, $char_rotate_amount);
+      $char_size  = $char_initial_size + rand(-$char_size_amount, $char_size_amount);
+      $font = variable_get("textimage_captcha_fonts_path", "") .'/'. $fonts[rand(0, count($fonts)-1)];
 
       // Find height and width of the character
-      $bbox = imagettfbbox($charSize, $charAngle, $font, $char);
-      $charWidth = max($bbox[0],$bbox[2],$bbox[4],$bbox[6]) - min($bbox[0],$bbox[2],$bbox[4],$bbox[6]);
-      $charHeight = abs(max($bbox[1],$bbox[3])) - min($bbox[5],$bbox[7]);
+      $bbox = imagettfbbox($char_size, $char_angle, $font, $char);
+      $char_width = max($bbox[0], $bbox[2], $bbox[4], $bbox[6]) - min($bbox[0], $bbox[2], $bbox[4], $bbox[6]);
+      $char_height = abs(max($bbox[1], $bbox[3])) - min($bbox[5], $bbox[7]);
 
       // Define the x and y position
-      $charSpacing = rand($charSpacingMin, $charSpacingMax);
-      $x = $imageWidth + $charSpacing;
-      $y = ($charHeight + rand(0,$charJiggleAmount));
-
-      $characterDetails[] = array (
-        "size"  => $charSize,
-        "angle" => $charAngle,
+      $char_spacing = rand($char_spacing_min, $char_spacing_max);
+      $x = $image_width + $char_spacing;
+      $y = ($char_height + rand(0, $char_jiggle_amount));
+
+      $character_details[] = array(
+        "size"  => $char_size,
+        "angle" => $char_angle,
         "x"     => $x,
         "y"     => $y,
         "font"  => $font,
@@ -235,18 +236,19 @@ function _textimage_captcha_image() {
       );
 
       // Increment the image size
-      $imageWidth  = $x + $charWidth;
-      $imageHeight = max($imageHeight,$y+$charJiggleAmount);
+      $image_width  = $x + $char_width;
+      $image_height = max($image_height, $y+$char_jiggle_amount);
     }
 
     // Create the image based off the string length and margin
     if (count($images) > 0) {
       // We're going to be using an image, and need a tranparent background to start with
-      $im = _textimage_create_transparent_image($imageWidth+2*$imageMargin, $imageHeight+2*$imageMargin);
+      $im = _textimage_create_transparent_image($image_width+2*$image_margin, $image_height+2*$image_margin);
       $noisecolor = imagecolorallocatealpha($im, 0, 0, 0, 127);
-    } else {
+    }
+    else {
       // Just make a plain-jane color brackground
-      $im = imagecreatetruecolor($imageWidth+2*$imageMargin, $imageHeight+2*$imageMargin);
+      $im = imagecreatetruecolor($image_width+2*$image_margin, $image_height+2*$image_margin);
       $background = imagecolorallocate($im, rand(180, 250), rand(180, 250), rand(180, 250));
       $noisecolor = $background;
       imagefill($im, 0, 0, $background);
@@ -255,9 +257,9 @@ function _textimage_captcha_image() {
     // Specify colors to be used in the image
     $foreground = imagecolorallocate($im, rand(0, 80), rand(0, 80), rand(0, 80));
 
-    foreach($characterDetails as $char) {
+    foreach ($character_details as $char) {
       // draw character
-      imagettftext($im,$char['size'],$char['angle'],$char['x']+$imageMargin,$char['y']+$imageMargin,$foreground,$char['font'],$char['char']);
+      imagettftext($im, $char['size'], $char['angle'], $char['x']+$image_margin, $char['y']+$image_margin, $foreground, $char['font'], $char['char']);
     }
 
   }
@@ -266,17 +268,18 @@ function _textimage_captcha_image() {
     // write text using a built-in font
     $x = 0;
     $y = 0;
-    $imageWidth = 60 + drupal_strlen($string)*$charSpacingMax*.35;
-    $imageHeight = 30 + $charJiggleAmount;
+    $image_width = 60 + drupal_strlen($string)*$char_spacing_max* . 35;
+    $image_height = 30 + $char_jiggle_amount;
 
     // Create the image
     if (count($images) > 0 && function_exists(imagecolorallocatealpha)) {
       // We're going to be using an image, and need a tranparent background to start with
-      $im = _textimage_create_transparent_image($imageWidth, $imageHeight);
+      $im = _textimage_create_transparent_image($image_width, $image_height);
       $noisecolor = imagecolorallocatealpha($im, 0, 0, 0, 127);
-    } else {
+    }
+    else {
       // Just make a plain-jane color brackground
-      $im = imagecreatetruecolor($imageWidth, $imageHeight);
+      $im = imagecreatetruecolor($image_width, $image_height);
       $background = imagecolorallocate($im, rand(180, 250), rand(180, 250), rand(180, 250));
       $noisecolor = $background;
       imagefill($im, 0, 0, $background);
@@ -284,25 +287,26 @@ function _textimage_captcha_image() {
 
     // Add the text
     for ($i=0;$i<drupal_strlen($string);$i++) {
-      imagestring($im,max(2,5-rand(0,$charSizeAmount)),$x,$y,drupal_substr($string,$i,1),$foreground);
-      $x += rand(10+$charSpacingMin,10+$charSpacingMax);
-      $y = $imageMargin + rand(0,$charJiggleAmount);
+      imagestring($im, max(2, 5-rand(0, $char_size_amount)), $x, $y, drupal_substr($string, $i, 1), $foreground);
+      $x += rand(10+$char_spacing_min, 10+$char_spacing_max);
+      $y = $image_margin + rand(0, ggle_amount);
     }
 
     // Scale the image according to the user defined font size and add the margin
-    $imageWidth  = imagesx($im) * ($charInitialSize * .08) + $imageMargin;
-    $imageHeight = imagesy($im) * ($charInitialSize * .08) + $imageMargin;
+    $image_width  = imagesx($im) * ($char_initial_size * .08) + $image_margin;
+    $image_height = imagesy($im) * ($char_initial_size * .08) + $image_margin;
 
     if (count($images) > 0) {
       // Prepare a larger image with a background image
-      $im2 = _textimage_create_transparent_image($imageWidth, $imageHeight);
-    } else {
+      $im2 = _textimage_create_transparent_image($image_width, $image_height);
+    }
+    else {
       // Prepare a larger image with a solid color
-      $im2 = imagecreatetruecolor($imageWidth, $imageHeight);
+      $im2 = imagecreatetruecolor($image_width, $image_height);
       imagefill($im2, 0, 0, $background);
     }
 
-    $result = imagecopyresampled ($im2, $im, $imageMargin, $imageMargin, 0, 0, $imageWidth, $imageHeight, imagesx($im), imagesy($im));
+    $result = imagecopyresampled($im2, $im, $image_margin, $image_margin, 0, 0, $image_width, $image_height, imagesx($im), imagesy($im));
     $im = $im2;
   }
 
@@ -310,22 +314,22 @@ function _textimage_captcha_image() {
   imageline($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), $foreground);
 
   // Add Noise
-  for ($x=0; $x<$imageWidth; $x++) {
-    for ($row=0; $row<$imageNoise;$row++) {
-      $y = rand(0,$imageHeight);
+  for ($x=0; $x<$image_width; $x++) {
+    for ($row=0; $row<$image_noise;$row++) {
+      $y = rand(0, $image_height);
       imagesetpixel($im, $x, $y, $noisecolor);
     }
   }
   // Add Lines and Ellipses
-  for ($x=0; $x<$imageLines;$x++) {
-    imageline($im, rand(0, $imageWidth), rand(0, $imageHeight), rand(0, $imageWidth), rand(0, $imageHeight), $noisecolor);
-    imageellipse($im, rand(0, $imageWidth), rand(0, $imageHeight), rand(0, $imageWidth), rand(0, $imageHeight), $noisecolor);
+  for ($x=0; $x<$image_lines;$x++) {
+    imageline($im, rand(0, $image_width), rand(0, $image_height), rand(0, $image_width), rand(0, $image_height), $noisecolor);
+    imageellipse($im, rand(0, $image_width), rand(0, $image_height), rand(0, $image_width), rand(0, $image_height), $noisecolor);
   }
 
   // Fill image with a random background image if available
   if (count($images) > 0) {
-    $image = $images[rand(0,count($images)-1)];
-    _textimage_captcha_apply_background_image($im,$image);
+    $image = $images[rand(0, count($images)-1)];
+    _textimage_captcha_apply_background_image($im, $image);
   }
 
   //output to browser
@@ -335,45 +339,45 @@ function _textimage_captcha_image() {
 }
 
 /**
-* Overlays an image to the supplied image resource
-*/
-function _textimage_captcha_apply_background_image (&$imageResource, $imageFile) {
-  $backgroundResource = image_gd_open($imageFile,substr($imageFile,-3));
+ * Overlays an image to the supplied image resource
+ */
+function _textimage_captcha_apply_background_image(&$image_resource, $image_file) {
+  $background_resource = image_gd_open($image_file, drupal_substr($image_file, -3));
   // Copy the text onto the background
-  $backX = imagesx($backgroundResource);
-  $backY = imagesy($backgroundResource);
-  $textX = imagesx($imageResource);
-  $textY = imagesy($imageResource);
+  $back_x = imagesx($background_resource);
+  $back_y = imagesy($background_resource);
+  $text_x = imagesx($image_resource);
+  $text_y = imagesy($image_resource);
 
-  $randomBackX = rand(0,$backX-$textX);
-  $randomBackY = rand(0,$backY-$textY);
+  $randomback_x = rand(0, $back_x-$text_x);
+  $randomback_y = rand(0, $back_y-$text_y);
 
   // Place the text onto a random location of the background image
-  imagecopyresampled($backgroundResource,$imageResource,$randomBackX,$randomBackY,0,0,$textX,$textY,$textX,$textY);
+  imagecopyresampled($background_resource, $image_resource, $randomback_x, $randomback_y, 0, 0, $text_x, $text_y, $text_x, $text_y);
   // Crop the background image to the original image size
-  imagecopyresampled($imageResource,$backgroundResource,0,0,$randomBackX,$randomBackY,$textX,$textY,$textX,$textY);
+  imagecopyresampled($image_resource, $background_resource, 0, 0, $randomback_x, $randomback_y, $text_x, $text_y, $text_x, $text_y);
 }
 
 /**
-* Returns a random string for use in a captcha
-*/
+ * Returns a random string for use in a captcha
+ */
 function _textimage_captcha_code() {
   $consts='bcdgjxvmnprst';
   $vowels='aeiou';
 
   for ($x=0; $x < 6; $x++) {
-    mt_srand ((double) microtime() * 1000000);
-    $const[$x] = drupal_substr($consts,mt_rand(0,drupal_strlen($consts)-1),1);
-    $vow[$x] = drupal_substr($vowels,mt_rand(0,drupal_strlen($vowels)-1),1);
+    mt_srand((double) microtime() * 1000000);
+    $const[$x] = drupal_substr($consts, mt_rand(0, drupal_strlen($consts)-1), 1);
+    $vow[$x] = drupal_substr($vowels, mt_rand(0, drupal_strlen($vowels)-1), 1);
   }
 
-  $string = $const[0] . $vow[0] .$const[2] . $const[1] . $vow[1] . $const[3] . $vow[3] . $const[4];
-  $string = drupal_substr($string,0,rand(4,6));
+  $string = $const[0] . $vow[0] . $const[2] . $const[1] . $vow[1] . $const[3] . $vow[3] . $const[4];
+  $string = drupal_substr($string, 0, rand(4, 6));
 
   //everytime we create a new code, we write it to session
   $_SESSION['captcha'] = drupal_strtolower($string);
 
-  if(variable_get('textimage_captcha_use_only_upper',0)) {
+  if (variable_get('textimage_captcha_use_only_upper', 0)) {
     $string = drupal_strtoupper($string);
   }
 
@@ -401,28 +405,28 @@ function textimage_captchavalidate(&$cap
 
 
 /**
- * Implementation of hook_captcha
+ * Implementation of hook_captcha().
  */
 function captcha_captcha() {
   $args = func_get_args();
-  $op = array_shift($args); 
-  switch($op) {
+  $op = array_shift($args);
+  switch ($op) {
     case 'list':
       return array("Image Captcha");
     case 'generate':
       $captcha_type = array_shift($args);
       $result = array();
-      if($captcha_type == "Image Captcha") {
- 
+      if ($captcha_type == "Image Captcha") {
+
         $result['value'] = _textimage_captcha_code();
-        $result['form']['captcha_challenge']  = array (
+        $result['form']['captcha_challenge'] = array(
           '#type' => 'textfield',
           '#title' => t('Captcha Validation'),
           '#default_value' => '',
           '#required' => TRUE,
           '#validate' => array('_captcha_validate' => array()),
           '#description' => t('Please type in the letters/numbers that are shown in the image above.'),
-          '#prefix' => '<div class="textimage-challenge"><img src="' . url('_textimage/image/'.time()) . '" alt="'.t('Captcha Image: you will need to recognize the text in it.').'"/></div>',
+          '#prefix' => '<div class="textimage-challenge"><img src="'. url('_textimage/image/'. time()) .'" alt="'. t('Captcha Image: you will need to recognize the text in it.') .'"/></div>',
         );
 
       }
Only in HEAD/: po
diff -urp HEAD/textimage.info 6.x-1.x-dev/textimage.info
--- HEAD/textimage.info	2008-05-26 10:31:32.000000000 +1000
+++ 6.x-1.x-dev/textimage.info	2008-05-26 10:49:17.000000000 +1000
@@ -1,3 +1,4 @@
 ; $Id: $
 name = Text Image
-description = "Provides text to image manipulations and image based captcha challenge (with Captcha module)."
+description = Provides text to image manipulations and image based captcha challenge (with Captcha module).
+core = 6.x
\ No newline at end of file
diff -urp HEAD/textimage.install 6.x-1.x-dev/textimage.install
--- HEAD/textimage.install	2008-05-26 10:31:43.000000000 +1000
+++ 6.x-1.x-dev/textimage.install	2008-05-26 13:59:46.000000000 +1000
@@ -1,39 +1,49 @@
 <?php
 // $Id: textimage.install,v 1.2 2007/02/06 02:29:38 wundo Exp $
 
+/**
+ * @file
+ * TODO: http://drupal.org/node/1354#files
+ */
+
+function textimage_schema() {
+  $schema['textimage_preset'] = array(
+    'fields' => array(
+      'pid' => array(
+        'type' => 'serial',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+      ),
+      'name' => array(
+        'type' => 'varchar',
+        'length' => 255,
+        'not null' => TRUE,
+      ),
+      'settings' => array(
+        'type' => 'text',
+        'not null' => TRUE,
+      ),
+    ),
+    'primary key' => array('pid'),
+  );
+
+  return $schema;
+}
+
 function textimage_install() {
-  switch ($GLOBALS['db_type']) {
-    case 'mysql':
-    case 'mysqli':
-      db_query('CREATE TABLE {textimage_preset} (
-        pid INT UNSIGNED NOT NULL PRIMARY KEY,
-        name VARCHAR(255) NOT NULL DEFAULT \'\',
-        settings TEXT NOT NULL )
-        /*!40100 DEFAULT CHARACTER SET utf8 */'
-      );
-
-      break;
-
-    case 'pgsql':
-      db_query('CREATE TABLE {textimage_preset} (
-        pid INTEGER NOT NULL CHECK (presetid > 0),
-        name VARCHAR(255) NOT NULL DEFAULT \'\',
-        settings TEXT NOT NULL DEFAULT \'\'
-        PRIMARY KEY (presetid));'
-      );
-      db_query("CREATE SEQUENCE textimage_preset_presetid_seq INCREMENT 1 START 1;");
-      break;
-  }
+  drupal_install_schema('textimage');
 }
 
 function textimage_uninstall() {
+  drupal_uninstall_schema('textimage');
+
   include_once(drupal_get_path('module', 'textimage') .'/textimage.module');
-  
-  db_query('DROP TABLE {textimage_preset}');
+
   $path = realpath(file_directory_path() .'/textimage');
-  if($path != FALSE)
+  if ($path != FALSE) {
     _textimage_recursive_delete($path);
-  
+  }
+
   variable_del('textimage_fonts_path');
   variable_del('textimage_images_path');
   variable_del('textimage_captcha_fonts_path');
@@ -47,56 +57,4 @@ function textimage_uninstall() {
   variable_del('textimage_captcha_image_noise');
   variable_del('textimage_captcha_image_lines');
   variable_del('textimage_captcha_image_margin');
-}
-
-
-// Install the textimage tables and seperate variable names for captcha specific variables
-function textimage_update_1() {
-  $ret = array();
-  switch ($GLOBALS['db_type']) {
-    case 'mysql':
-    case 'mysqli':
-      $ret[] = update_sql('CREATE TABLE {textimage_preset} (
-        pid INT UNSIGNED NOT NULL PRIMARY KEY,
-        name VARCHAR(255) NOT NULL DEFAULT \'\',
-        settings TEXT NOT NULL DEFAULT \'\' )
-        /*!40100 DEFAULT CHARACTER SET utf8 */'
-      );
-
-      break;
-
-    case 'pgsql':
-      $ret[] = update_sql('CREATE TABLE {textimage_preset} (
-        pid INTEGER NOT NULL CHECK (presetid > 0),
-        name VARCHAR(255) NOT NULL DEFAULT \'\',
-        settings TEXT NOT NULL DEFAULT \'\'
-        PRIMARY KEY (presetid));'
-      );
-      $ret[] = update_sql("CREATE SEQUENCE textimage_preset_presetid_seq INCREMENT 1 START 1;");
-      break;
-  }
-  
-  if (variable_get('textimage_fonts_path', '0')) variable_set('textimage_captcha_fonts_path', variable_get('textimage_fonts_path', ''));
-  if (variable_get('textimage_font_size', '0')) variable_set('textimage_captcha_font_size', variable_get('textimage_font_size', '24'));
-  if (variable_get('textimage_char_spacing_max', '0')) variable_set('textimage_captcha_char_spacing_max', variable_get('textimage_char_spacing_max', '10'));
-  if (variable_get('textimage_char_jiggle_amount', '0')) variable_set('textimage_captcha_char_jiggle_amount', variable_get('textimage_char_jiggle_amount', '5'));
-  if (variable_get('textimage_char_rotate_amount', '0')) variable_set('textimage_captcha_char_rotate_amount', variable_get('textimage_char_rotate_amount', '5'));
-  if (variable_get('textimage_char_size_amount', '0')) variable_set('textimage_captcha_char_size_amount', variable_get('textimage_char_size_amount', '2'));
-  if (variable_get('textimage_use_only_upper', '0')) variable_set('textimage_captcha_use_only_upper', variable_get('textimage_use_only_upper', '0'));
-  if (variable_get('textimage_images_path', '0')) variable_set('textimage_captcha_images_path', variable_get('textimage_images_path', ''));
-  if (variable_get('textimage_image_noise', '0')) variable_set('textimage_captcha_image_noise', variable_get('textimage_image_noise', '4'));
-  if (variable_get('textimage_image_lines', '0')) variable_set('textimage_captcha_image_lines', variable_get('textimage_image_lines', '4'));
-  if (variable_get('textimage_image_margin', '0')) variable_set('textimage_captcha_image_margin', variable_get('textimage_image_margin', '10'));
-  
-  variable_del('textimage_font_size');
-  variable_del('textimage_char_spacing_max');
-  variable_del('textimage_char_jiggle_amount');
-  variable_del('textimage_char_rotate_amount');
-  variable_del('textimage_char_size_amount');
-  variable_del('textimage_use_only_upper');
-  variable_del('textimage_image_noise');
-  variable_del('textimage_image_lines');
-  variable_del('textimage_image_margin');
-  
-  return $ret;
-}
+}
\ No newline at end of file
diff -urp HEAD/textimage.module 6.x-1.x-dev/textimage.module
--- HEAD/textimage.module	2008-05-26 14:03:40.000000000 +1000
+++ 6.x-1.x-dev/textimage.module	2008-05-26 14:00:17.000000000 +1000
@@ -2,6 +2,11 @@
 // $Id: textimage.module,v 1.16 2007/05/10 22:33:48 wundo Exp $
 
 /**
+ * @file
+ * TODO: http://drupal.org/node/1354#files
+ */
+
+/**
  * Matches all 'P' Unicode character classes (punctuation)
  */
 define('PREG_CLASS_PUNCTUATION',
@@ -24,24 +29,24 @@ define('PREG_CLASS_PUNCTUATION',
 /**
  * Matches all 'Z' Unicode character classes (separators)
  */
-define('PREG_CLASS_SEPARATOR','\x{20}\x{a0}\x{1680}\x{180e}\x{2000}-\x{200a}\x{2028}\x{2029}\x{202f}\x{205f}\x{3000}');
+define('PREG_CLASS_SEPARATOR', '\x{20}\x{a0}\x{1680}\x{180e}\x{2000}-\x{200a}\x{2028}\x{2029}\x{202f}\x{205f}\x{3000}');
 
 
 if (module_exists('captcha')) {
   include_once(drupal_get_path('module', 'textimage') .'/captcha.inc');
 }
 
-define('ALIGN_LEFT',1);
-define('ALIGN_CENTER',2);
-define('ALIGN_RIGHT',3);
+define('ALIGN_LEFT', 1);
+define('ALIGN_CENTER', 2);
+define('ALIGN_RIGHT', 3);
 
 /**
-* Implementation of hook_help().
-*/
-function textimage_help($section) {
+ * Implementation of hook_help().
+ */
+function textimage_help($path, $arg) {
   $output = "";
 
-  switch ($section) {
+  switch ($path) {
     case 'admin/help#textimage':
       $output .= '<h2 id="textimage-introduction">The dynamic text to image generator!</h2>';
       $output .= '<p>Text image is a module which allows you to create dynamic images using any font installed on the server.</p>';
@@ -63,9 +68,9 @@ function textimage_help($section) {
       $output = t($output, array(
         '!config' => url('admin/settings/textimage'),
         '!captcha' => url('admin/settings/textimage/captcha'),
-        '!example1' => base_path() . drupal_get_path('module', 'textimage') . '/misc/example1.png',
-        '!example2' => base_path() . drupal_get_path('module', 'textimage') . '/misc/example2.png',
-        '!example3' => base_path() . drupal_get_path('module', 'textimage') . '/misc/example3.png',
+        '!example1' => base_path() . drupal_get_path('module', 'textimage') .'/misc/example1.png',
+        '!example2' => base_path() . drupal_get_path('module', 'textimage') .'/misc/example2.png',
+        '!example3' => base_path() . drupal_get_path('module', 'textimage') .'/misc/example3.png',
       ));
       break;
     case 'admin/build/modules#description':
@@ -78,107 +83,114 @@ function textimage_help($section) {
 }
 
 /**
-* Implementation of hook_menu().
-*/
-function textimage_menu($may_cache) {
-  $items = array();
-  
-  if ($may_cache) {
-    $items[] = array(
-      'path' => file_directory_path() . '/textimage',
-      'callback' => 'textimage_image',
-      'access' => true,
-      'type' => MENU_CALLBACK,
-    );
-    
-    $items[] = array(
-      'path' => 'admin/settings/textimage',
-      'title' => t('Text Image'),
-      'description' => t('Configure text to image preset functions.') . (module_exists('captcha') ? ' ' . t('Set the options for image based captchas.') : ''),
-      'callback' => 'drupal_get_form',
-      'callback arguments' => array('textimage_settings_form'),
-      'access' => user_access('administer site configuration'),
-      'type' => MENU_NORMAL_ITEM
-    );
-    
-    $items[] = array(
-      'path' => 'admin/settings/textimage/settings',
-      'title' => t('Settings'),
-      'callback' => 'drupal_get_form', 
-      'callback arguments' => array('textimage_settings_form'),
-      'access' => user_access('administer site configuration'),
-      'weight' => 0,
-      'type' => MENU_DEFAULT_LOCAL_TASK
-    );
-    $items[] = array(
-      'path' => 'admin/settings/textimage/list',
-      'title' => t('List presets'),
-      'callback' => 'textimage_preset_list', 
-      'access' => user_access('administer site configuration'),
-      'weight' => 1,
-      'type' => MENU_LOCAL_TASK
-    );
-    $items[] = array(
-      'path' => 'admin/settings/textimage/new',
-      'title' => t('New preset'),
-      'callback' => 'drupal_get_form',
-      'callback arguments' => array('textimage_preset_edit', 'new'),
-      'access' => user_access('administer site configuration'),
-      'weight' => 2,
+ * Implementation of hook_theme().
+ */
+function textimage_theme() {
+  return array(
+    'textimage_image' => array(
+      'arguments' => array(
+        'preset',
+        'text',
+        'additional_text' => array(),
+        'format' => 'png',
+        'alt' => '',
+        'title' => '',
+        'attributes' => array(),
+        'getsize' => TRUE,
+      ),
+    ),
+  );
+}
+
+/**
+ * Implementation of hook_menu().
+ */
+function textimage_menu() {
+  $items[file_directory_path() .'/textimage'] = array(
+    'page callback' => 'textimage_image',
+    'access arguments' => array('administer site configuration'),
+    'type' => MENU_CALLBACK,
+  );
+  $items['admin/settings/textimage'] = array(
+    'title' => 'Text Image',
+    'description' => 'Configure text to image preset functions.'. (module_exists('captcha') ? ' Set the options for image based captchas.' : ''),
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('textimage_settings_form'),
+    'access arguments' => array('administer site configuration'),
+    'type' => MENU_NORMAL_ITEM
+  );
+  $items['admin/settings/textimage/settings'] = array(
+    'title' => 'Settings',
+    'page callback' => 'drupal_get_form', 
+    'page arguments' => array('textimage_settings_form'),
+    'access arguments' => array('administer site configuration'),
+    'weight' => 0,
+    'type' => MENU_DEFAULT_LOCAL_TASK
+  );
+  $items['admin/settings/textimage/list'] = array(
+    'title' => 'List presets',
+    'page callback' => 'textimage_preset_list', 
+    'access arguments' => array('administer site configuration'),
+    'weight' => 1,
+    'type' => MENU_LOCAL_TASK
+  );
+  $items['admin/settings/textimage/new'] = array(
+    'title' => 'New preset',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('textimage_preset_edit', 'new'),
+    'access arguments' => array('administer site configuration'),
+    'weight' => 2,
+    'type' => MENU_LOCAL_TASK
+  );
+  $items['admin/settings/textimage/preset'] = array(
+    'title' => 'Edit Preset',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('textimage_preset_edit'),
+    'access arguments' => array('administer site configuration'),
+    'type' => MENU_CALLBACK,
+  );
+
+  if (module_exists('captcha')) {
+    $items['admin/settings/textimage/captcha'] = array(
+      'title' => 'Captcha display',
+      'page callback' => 'drupal_get_form',
+      'page arguments' => array('textimage_captcha_settings_form'),
+      'access arguments' => array('administer site configuration'),
+      'weight' => 5,
       'type' => MENU_LOCAL_TASK
     );
-    $items[] = array(
-      'path' => 'admin/settings/textimage/preset',
-      'title' => t('Edit Preset'),
-      'callback' => 'drupal_get_form',
-      'callback arguments' => array('textimage_preset_edit'),
-      'access' => user_access('administer site configuration'),
-      'type' => MENU_CALLBACK,
-    );
-    
-    if (module_exists('captcha')) {
-      $items[] = array(
-        'path' => 'admin/settings/textimage/captcha',
-        'title' => t('Captcha display'),
-        'callback' => 'drupal_get_form',
-        'callback arguments' => array('textimage_captcha_settings_form'),
-        'access' => user_access('administer site configuration'),
-        'weight' => 5,
-        'type' => MENU_LOCAL_TASK
-      );
-    }
-  }
-  else {
-    $suffix = arg(2) != null ? '/' . arg(2) : '';
-    $items[] = array(
-      'path' => '_textimage/image'.$suffix, 'title' => t('textimage'),
-      'callback' => '_textimage_captcha_image', 
-      'access' => user_access('access textimages'),
-      'type' => MENU_CALLBACK
-    );
-    $items[] = array(
-      'path' => 'admin/settings/textimage/preset/' . arg(4) . '/delete',
-      'title' => t('Edit Preset'),
-      'callback' => 'drupal_get_form',
-      'callback arguments' => array('textimage_preset_delete_confirm', arg(4)),
-      'access' => user_access('administer site configuration'),
-      'type' => MENU_CALLBACK,
-    );
-    $items[] = array(
-      'path' => 'admin/settings/textimage/preset/' . arg(4) . '/flush',
-      'title' => t('Flush Preset Cache'),
-      'callback' => 'drupal_get_form',
-      'callback arguments' => array('textimage_preset_flush_confirm', arg(4)),
-      'access' => user_access('administer site configuration'),
-      'type' => MENU_CALLBACK,
-    );
   }
+
+  $items['_textimage/image/%'] = array(
+    'title' => 'textimage',
+    'load arguments' => array(2),
+    'page callback' => '_textimage_captcha_image',
+    'access arguments' => array('access textimages'),
+    'type' => MENU_CALLBACK
+  );
+  $items['admin/settings/textimage/preset/%/delete'] = array(
+    'title' => 'Edit Preset',
+    'load arguments' => array(4),
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('textimage_preset_delete_confirm', 4),
+    'access arguments' => array('administer site configuration'),
+    'type' => MENU_CALLBACK,
+  );
+  $items['admin/settings/textimage/preset/%/flush'] = array(
+    'title' => 'Flush Preset Cache',
+    'load arguments' => array(4),
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('textimage_preset_flush_confirm', 4),
+    'access arguments' => array('administer site configuration'),
+    'type' => MENU_CALLBACK,
+  );
+
   return $items;
 }
 
 /**
-* Implementation of hook_perm().
-*/
+ * Implementation of hook_perm().
+ */
 function textimage_perm() {
   return array('access textimages');
 }
@@ -212,15 +224,15 @@ function textimage_settings_form() {
 
 
   if (isset($fonts_path)) {
-    $imagefontinfo .= t('Number of fonts found: ').count(_textimage_font_list($fonts_path));
+    $imagefontinfo .= t('Number of fonts found: ') . count(_textimage_font_list($fonts_path));
   }
   if (isset($images_path)) {
-    $imagefontinfo .= '<br />'.t('Number of background images found: ').count(_textimage_image_list($images_path));
+    $imagefontinfo .= '<br />'. t('Number of background images found: ') . count(_textimage_image_list($images_path));
   }
 
   $gdinfo = gd_info();
-  $imagefontinfo .= '<br />'.t('GD Version: ').$gdinfo["GD Version"];
-  $imagefontinfo .= '<br />'.t(' FreeType Support: ');
+  $imagefontinfo .= '<br />'. t('GD Version: ') . $gdinfo["GD Version"];
+  $imagefontinfo .= '<br />'. t(' FreeType Support: ');
   $imagefontinfo .= ($gdinfo["FreeType Support"] == true) ? t('True') : t('False');
   $imagefontinfo .= '<br />';
   
@@ -235,7 +247,7 @@ function textimage_settings_form() {
     '#collapsed' => FALSE
   );
   
-  $form['info']['textimage_info'] = array (
+  $form['info']['textimage_info'] = array(
    '#type' => 'item',
    '#value' => $imagefontinfo,
   );
@@ -269,12 +281,12 @@ function textimage_settings_form() {
   return system_settings_form($form);
 }
 
-function textimage_settings_form_validate($form_id, $form_values) {
+function textimage_settings_form_validate($form, &$form_state) {
   //check for valid font path
-  if ($form_values['textimage_fonts_path'] !="" && !is_dir(rtrim($form_values['textimage_fonts_path'], '\\/')))
+  if ($form_state['values']['textimage_fonts_path'] !="" && !is_dir(rtrim($form_state['values']['textimage_fonts_path'], '\\/')))
     form_set_error('textimage_fonts_path', t('The entered font path is invalid'));
   //check for valid image path
-  if ($form_values['textimage_images_path'] !="" && !is_dir(rtrim($form_values['textimage_images_path'], '\\/')))
+  if ($form_state['values']['textimage_images_path'] !="" && !is_dir(rtrim($form_state['values']['textimage_images_path'], '\\/')))
     form_set_error('textimage_images_path', t('The entered image path is invalid'));
 }
 
@@ -283,20 +295,20 @@ function textimage_settings_page() {
   return $output;
 }
 
-function textimage_preset_edit($preset_id) {
+function textimage_preset_edit(&$form_state, $preset_id) {
   if (is_numeric($preset_id)) {
     $preset = _textimage_preset_load($preset_id);
   }
   else {
     $preset = array();
   }
-  
+
   $fonts_path = variable_get('textimage_fonts_path', '');
   $font_options = drupal_map_assoc(_textimage_font_list($fonts_path));
-  
+
   $images_path = variable_get('textimage_images_path', '');
   $image_files = drupal_map_assoc(_textimage_image_list($images_path));
-  
+
   $image_presets = array();
   $presets = textimage_get_presets();
   foreach ($presets as $p) {
@@ -304,7 +316,7 @@ function textimage_preset_edit($preset_i
       $image_presets[$p['pid']] = $p['name'];
     }
   }
-  
+
   $image_options = array(
     t('Default:') => array('' => t('Default (use background color)')),
     t('Use the result of Text Image Preset:') => $image_presets,
@@ -313,12 +325,12 @@ function textimage_preset_edit($preset_i
 
   $form = array();
   $form['#tree'] = TRUE;
-  
+
   $form['preset_id'] = array(
     '#type' => 'value',
     '#value' => $preset_id,
   );
-  
+
   $form['name'] = array(
     '#type' => 'textfield',
     '#title' => t('Preset Name'),
@@ -326,7 +338,7 @@ function textimage_preset_edit($preset_i
     '#default_value' => $preset['name'],
     '#required' => TRUE,
   );
-  
+
   $form['settings']['description'] = array(
     '#type' => 'textarea',
     '#title' => t('Description'),
@@ -334,7 +346,7 @@ function textimage_preset_edit($preset_i
     '#default_value' => $preset['settings']['description'],
     '#rows' => 1,
   );
-  
+
   $form['settings']['text'] = array(
     '#type' => 'fieldset',
     '#title' => t('Text Settings'),
@@ -459,7 +471,7 @@ function textimage_preset_edit($preset_i
     '#size' => 4,
     '#validate' => array('_textimage_number_validate' => array('margin_left')),
   );
-  
+
   $form['settings']['background'] = array(
     '#type' => 'fieldset',
     '#title' => t('Background'),
@@ -499,40 +511,39 @@ function textimage_preset_edit($preset_i
     '#size' => 4,
     '#validate' => array('_textimage_number_validate' => array('yoffset')),
   );
-  
+
   $form['submit'] = array(
     '#type' => 'submit',
     '#value' => t('Submit'),
   );
-  
+
   return $form;
 }
 
-function textimage_preset_edit_validate($form_id, $form_values) {
+function textimage_preset_edit_validate($form, &$form_state) {
   // Check for illegal characters in preset names
-  if (preg_match('/[^0-9a-zA-Z_\-]/',$form_values['name'])) {
-    form_set_error('name',t('Please only use alphanumic characters, underscores (_), and hyphens (-) for preset names.'));
+  if (preg_match('/[^0-9a-zA-Z_\-]/', $form_state['values']['name'])) {
+    form_set_error('name', t('Please only use alphanumic characters, underscores (_), and hyphens (-) for preset names.'));
   }
-  
-  if ($form_values['preset_id'] == 'new') {
+  if ($form_state['values']['preset_id'] == 'new') {
     // Check for duplicate preset names
-    $preset = _textimage_preset_load_by_name($form_values['name']);
+    $preset = _textimage_preset_load_by_name($form_state['values']['name']);
     if ($preset['name']) {
-      form_set_error('name', t('The name %name is already in use by another preset.', array('%name' => $form_values['name'])));
+      form_set_error('name', t('The name %name is already in use by another preset.', array('%name' => $form_state['values']['name'])));
     }
   }
 }
 
-function textimage_preset_edit_submit($form_id, $form_values) {
-  if ($form_values['preset_id'] == 'new') {
-    $return = _textimage_preset_create($form_values['name'], $form_values['settings']);
+function textimage_preset_edit_submit($form, &$form_state) {
+  if ($form_state['values']['preset_id'] == 'new') {
+    $return = _textimage_preset_create($form_state['values']['name'], $form_state['values']['settings']);
   }
-  elseif (is_numeric($form_values['preset_id'])) {
-    $return = _textimage_preset_update($form_values['preset_id'], $form_values['name'], $form_values['settings']);
+  elseif (is_numeric($form_state['values']['preset_id'])) {
+    $return = _textimage_preset_update($form_state['values']['preset_id'], $form_state['values']['name'], $form_state['values']['settings']);
   }
   
   if ($return) {
-    drupal_set_message(t('Updated preset %name', array('%name' => $form_values['name'])));
+    drupal_set_message(t('Updated preset %name', array('%name' => $form_state['values']['name'])));
     drupal_goto('admin/settings/textimage/list');
   }
   else {
@@ -548,11 +559,11 @@ function textimage_preset_list() {
   foreach ($presets as $name => $preset) {
     $row = array();
     $row[] = $name;
-    $row[] = $preset['settings']['text']['font'] . ' ' . $preset['settings']['text']['size'] . t('px');
+    $row[] = $preset['settings']['text']['font'] .' '. $preset['settings']['text']['size'] . t('px');
     $row[] = $preset['settings']['description'];
     $row[] = l(t('edit'), 'admin/settings/textimage/preset/'. $preset['pid']);
-    $row[] = l(t('delete'), 'admin/settings/textimage/preset/'. $preset['pid'] . '/delete');
-    $row[] = l(t('flush cache'), 'admin/settings/textimage/preset/'. $preset['pid'] . '/flush');
+    $row[] = l(t('delete'), 'admin/settings/textimage/preset/'. $preset['pid'] .'/delete');
+    $row[] = l(t('flush cache'), 'admin/settings/textimage/preset/'. $preset['pid'] .'/flush');
   
     $rows[] = $row;
   }
@@ -564,42 +575,42 @@ function textimage_preset_list() {
   return theme('table', $header, $rows);
 }
 
-function textimage_preset_delete_confirm($preset_id) {
+function textimage_preset_delete_confirm(&$form_state, $preset_id) {
   $preset = _textimage_preset_load($preset_id);
-  
+
   $form['pid'] = array('#type' => 'value', '#value' => $preset_id);
   $form['name'] = array('#type' => 'value', '#value' => $preset['name']);
-  
+
   return confirm_form($form,
     t('Are you sure you want to delete the preset %name?', array('%name' => $preset['name'])),
     $_GET['destination'] ? $_GET['destination'] : 'admin/settings/textimage/list',
     t('This action cannot be undone.'),
     t('Delete'), t('Cancel')
- );
+  );
 }
 
-function textimage_preset_delete_confirm_submit($form_id, $form_values) {
-  _textimage_preset_delete($form_values['pid']);
-  drupal_set_message(t('Deleted preset %name', array('%name' => $form_values['name'])));
+function textimage_preset_delete_confirm_submit($form, &$form_state) {
+  _textimage_preset_delete($form_state['values']['pid']);
+  drupal_set_message(t('Deleted preset %name', array('%name' => $form_state['values']['name'])));
   drupal_goto('admin/settings/textimage/list');
 }
 
-function textimage_preset_flush_confirm($preset_id) {
+function textimage_preset_flush_confirm(&$form_state, $preset_id) {
   $preset = _textimage_preset_load($preset_id);
-  
+
   $form['pid'] = array('#type' => 'value', '#value' => $preset_id);
   $form['name'] = array('#type' => 'value', '#value' => $preset['name']);
-  
+
   return confirm_form($form,
     t('Are you sure you want to flush the image cache for preset %name?', array('%name' => $preset['name'])),
     $_GET['destination'] ? $_GET['destination'] : 'admin/settings/textimage/list',
     t('This action cannot be undone.'),
     t('Flush Cache'), t('Cancel')
- );
+  );
 }
 
-function textimage_preset_flush_confirm_submit($form_id, $form_values) {
-  _textimage_preset_flush($form_values['pid']);
+function textimage_preset_flush_confirm_submit($form, &$form_state) {
+  _textimage_preset_flush($form_state['values']['pid']);
   drupal_goto('admin/settings/textimage/list');
 }
 
@@ -638,30 +649,29 @@ function textimage_get_presets() {
  */
 function textimage_image() {
   $args = func_get_args();
-  
+
   $preset_name = array_shift($args);
   $filename = array_pop($args);
   $additional_text = $args; 
-  
-  
+
   // Determine our output format
   preg_match('/\.([a-z]+)$/i', $filename, $matches);
   $format = $matches[1];
   if ($format == 'jpg') {
     $format = 'jpeg';
   }
-  
+
   // Determine the text to display
   $text = preg_replace('/\.([a-z]+)$/i', '', $filename);
-  
+
   // Integrety check
-  $output_function = 'image' . $format;
+  $output_function = 'image'. $format;
   if (!function_exists($output_function)) {
     $message = t('Unable to generate Text Image %text because the file extension is unsupported on this system. Files must have a .png, .jpg, or .gif extension.', array('%text' => $filename));
     watchdog('textimage', $message, WATCHDOG_ERROR);
     return $message;
   }
-  
+
   // Generate the image resource
   $preset = _textimage_preset_load_by_name($preset_name);
   // Check that it exists
@@ -674,7 +684,7 @@ function textimage_image() {
   $img = textimage_image_from_preset($preset['pid'], $text, $additional_text);
   
   // Display the image to be browser
-  header('Content-type: image/'.$format);
+  header('Content-type: image/'. $format);
   $output_function($img);
   
   // Save the result so we don't have to recreate
@@ -699,7 +709,7 @@ function textimage_image_from_preset($pr
   $preset = _textimage_preset_load($preset_id);
   $text = str_replace('_', ' ', $text);
 
-  $font = variable_get('textimage_fonts_path', '') . '/' . $preset['settings']['text']['font'];
+  $font = variable_get('textimage_fonts_path', '') .'/'. $preset['settings']['text']['font'];
 
   // Fill in default preset settings.
   $defaults = array(
@@ -757,10 +767,10 @@ function textimage_image_from_preset($pr
       break;
     
   }
-  if (function_exists('drupal_' . $case)) {
+  if (function_exists('drupal_'. $case)) {
     $text = drupal_strtoupper($text);
   }
-  
+
   // Generate the text image
   $img = textimage_text_to_image($text, $size, $font, $color, $back_color, $angle, $maximum_width, $fixed_width, $align);
   
@@ -887,9 +897,9 @@ function textimage_image_stroke_change_p
   // Generate a total alpha level for all analyzed pixels
   $total_alpha = 0;
   $total_colors = 0;
-  foreach($radial_coords as $coords) {
+  foreach ($radial_coords as $coords) {
     if ($coords['x'] >= 0 && $coords['y'] >= 0 && $coords['x'] < $width && $coords['y'] < $height) {
-       $xy_color = imagecolorsforindex($img, imagecolorat($img, $coords['x'], $coords['y']));
+      $xy_color = imagecolorsforindex($img, imagecolorat($img, $coords['x'], $coords['y']));
     }
     else {
       // This analized pixel is outside the dimensions of the image, record as transparent
@@ -923,12 +933,12 @@ function textimage_image_stroke_change_p
  * 
  * @param $directory_path
  *   String containing the path of the directory to check.
- */ 
+ */
 function textimage_directory_check($directory_path) {
   // create each directory necessary if it doesn't exist
-  foreach(explode('/', $directory_path) as $dir) {
+  foreach (explode('/', $directory_path) as $dir) {
     $dirs[] = $dir;
-    if (!file_check_directory(implode($dirs,'/'), FILE_CREATE_DIRECTORY)) {
+    if (!file_check_directory(implode($dirs, '/'), FILE_CREATE_DIRECTORY)) {
       return false;
     }
   }
@@ -956,14 +966,14 @@ function textimage_wrap_text($text, $fon
   while (true) {
     // Find the next wrap point (always after trailing whitespace).
     if (preg_match('/['. PREG_CLASS_PUNCTUATION .']['. PREG_CLASS_SEPARATOR .']*|['. PREG_CLASS_SEPARATOR .']+/u', $text, $match, PREG_OFFSET_CAPTURE, $end)) {
-      $end = $match[0][1] + strlen($match[0][0]);
+      $end = $match[0][1] + drupal_strlen($match[0][0]);
     }
     else {
-      $end = strlen($text);
+      $end = drupal_strlen($text);
     }
     
     // Fetch text, removing trailing white-space and measure it.
-    $line = preg_replace('/['. PREG_CLASS_SEPARATOR .']+$/u', '', substr($text, $begin, $end - $begin));
+    $line = preg_replace('/['. PREG_CLASS_SEPARATOR .']+$/u', '', drupal_substr($text, $begin, $end - $begin));
     $width = textimage_measure_text_width($line, $fontsize, $font);
 
     // See if $line extends past the available space.
@@ -971,17 +981,17 @@ function textimage_wrap_text($text, $fon
       // If this is the first word, we need to truncate it.
       if ($fit == $begin) {
         // Cut off letters until it fits.
-        while (strlen($line) > 0 && $width > $maximum_width) {
+        while (drupal_strlen($line) > 0 && $width > $maximum_width) {
           $line = drupal_substr($line, 0, -1);
           $width = textimage_measure_text_width($line, $fontsize, $font);
         }
         // If no fit was found, the image is too narrow..
-        $fit = strlen($line) ? $begin + strlen($line) : $end;
+        $fit = drupal_strlen($line) ? $begin + drupal_strlen($line) : $end;
       }
 
       // We have a valid fit for the next line. Insert a line-break and reset
       // the search interval.
-      $text = substr($text, 0, $fit) ."\n". substr($text, $fit);
+      $text = drupal_substr($text, 0, $fit) ."\n". drupal_substr($text, $fit);
       $end = $begin = ++$fit;
     }
     else {
@@ -989,7 +999,7 @@ function textimage_wrap_text($text, $fon
       $fit = $end;
     }
 
-    if ($end == strlen($text)) {
+    if ($end == drupal_strlen($text)) {
       // All text fits. No more changes are needed.
       break;
     }
@@ -1015,7 +1025,7 @@ function textimage_text_to_image($text, 
   $iw = abs($box[4] - $box[0]) + 4;
   $ih = abs($box[5] - $box[1]) + 4;
   
-  if($fixed_width) {
+  if ($fixed_width) {
     $background_width = $maximum_width;
   }
   else {
@@ -1038,7 +1048,7 @@ function textimage_text_to_image($text, 
   list($r, $g, $b) = _textimage_hex2rgb($foreground_color);
   $fore = imagecolorallocate($img, $r, $g, $b);
 
-  switch($align) {
+  switch ($align) {
     case ALIGN_RIGHT:
       $x = $maximum_width - $iw;
       break;
@@ -1081,12 +1091,11 @@ function _textimage_preset_load($id) {
  */
 
 function _textimage_preset_load_by_name($name) {
-  $result = db_query("SELECT pid, name, settings FROM {textimage_preset} WHERE name = '%s'", $name);
-  if (db_num_rows($result) == 0) {
+  if (db_query("SELECT COUNT(*) FROM {textimage_preset} WHERE name = '%s'", $name) == 0) {
     return false;
   }
   else {
-    $preset = db_fetch_array($result);
+    $preset = db_fetch_array(db_query("SELECT * FROM {textimage_preset} WHERE name = '%s'", $name));
     $preset['settings'] = unserialize($preset['settings']);
     return $preset;
   }
@@ -1098,8 +1107,7 @@ function _textimage_preset_load_by_name(
  *    name of the preset to be created.
  */
 function _textimage_preset_create($name, $settings) {
-  $next_id = db_next_id('{textimage_preset}_pid');
-  return db_query('INSERT INTO {textimage_preset} (pid, name, settings) VALUES (%d, \'%s\', \'%s\')', $next_id, $name, serialize($settings));
+  return db_query('INSERT INTO {textimage_preset} (name, settings) VALUES (\'%s\', \'%s\')', $name, serialize($settings));
 }
 
 /**
@@ -1144,12 +1152,12 @@ function _textimage_preset_flush($id) {
  *   An absolute filepath (relative to the filesystem) to delete
  */
 function _textimage_recursive_delete($path) {
-  $listing = $path . "/*";
-  foreach(glob($listing) as $file) {
-    if(is_file($file) === true) {
+  $listing = $path ."/*";
+  foreach (glob($listing) as $file) {
+    if (is_file($file) === true) {
       @unlink($file);
     }
-    elseif(is_dir($file) === true) {
+    elseif (is_dir($file) === true) {
       _textimage_recursive_delete($file);
       @rmdir($file);
     }
@@ -1158,13 +1166,13 @@ function _textimage_recursive_delete($pa
 }
 
 /**
-* Returns an array of files with TTF extensions in the specified directory.
-*/
+ * Returns an array of files with TTF extensions in the specified directory.
+ */
 function _textimage_font_list($fontdir) {
   $filelist = array();
   if (is_dir($fontdir) && $handle = opendir($fontdir)) {
     while ($file = readdir($handle)) {
-      if (preg_match("/\.ttf$/i",$file) == 1)
+      if (preg_match("/\.ttf$/i", $file) == 1)
         $filelist[] = $file;
     }
     closedir($handle);
@@ -1186,14 +1194,14 @@ function _textimage_hex_validate($field,
 }
 
 /**
-* Returns an array of files with jpg, png, and gif extensions in the specified directory.
-*/
+ * Returns an array of files with jpg, png, and gif extensions in the specified directory.
+ */
 function _textimage_image_list($imagesdir) {
   $filelist = array();
   if (is_dir($imagesdir) && $handle = opendir($imagesdir)) {
     while ($file = readdir($handle)) {
-      if (preg_match("/\.gif|\.png|\.jpg$/i",$file) == 1)
-        $filelist[] = $imagesdir.'/'.$file;
+      if (preg_match("/\.gif|\.png|\.jpg$/i", $file) == 1)
+        $filelist[] = $imagesdir .'/'. $file;
     }
     closedir($handle);
   }
@@ -1202,17 +1210,17 @@ function _textimage_image_list($imagesdi
 }
 
 /**
-* Creates transparent image resources for images with graphic backgrounds
-*/
+ * Creates transparent image resources for images with graphic backgrounds
+ */
 function _textimage_create_transparent_image($x, $y) {
   $i = imagecreatetruecolor($x, $y);
   $b = imagecreatefromstring(base64_decode(_textimage_blankpng()));
   imagealphablending($i, false);
   imagesavealpha($i, true);
-  imagecopyresized($i, $b ,0 ,0 ,0 ,0 ,$x, $y, imagesx($b), imagesy($b));
+  imagecopyresized($i, $b, 0, 0, 0, 0, $x, $y, imagesx($b), imagesy($b));
   return $i;
 }
- 
+
 function _textimage_blankpng() {
   $c  = "iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29m";
   $c .= "dHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAADqSURBVHjaYvz//z/DYAYAAcTEMMgBQAANegcCBNCg";
@@ -1229,18 +1237,18 @@ function _textimage_blankpng() {
  *
  */
 function _textimage_hex2rgb($hex) {
-  $hex = ltrim($hex,'#');
-  if (preg_match('/^[0-9a-f]{3}$/i',$hex)) {
+  $hex = ltrim($hex, '#');
+  if (preg_match('/^[0-9a-f]{3}$/i', $hex)) {
     // 'FA3' is the same as 'FFAA33' so r=FF, g=AA, b=33
-    $r = str_repeat($hex{0},2);
-    $g = str_repeat($hex{1},2);
-    $b = str_repeat($hex{2},2);
+    $r = str_repeat($hex{0}, 2);
+    $g = str_repeat($hex{1}, 2);
+    $b = str_repeat($hex{2}, 2);
   }
-  elseif (preg_match('/^[0-9a-f]{6}$/i',$hex)) {
+  elseif (preg_match('/^[0-9a-f]{6}$/i', $hex)) {
     // #FFAA33 or r=FF, g=AA, b=33
-    $r = substr($hex, 0, 2);
-    $g = substr($hex, 2, 2);
-    $b = substr($hex, 4, 2);
+    $r = drupal_substr($hex, 0, 2);
+    $g = drupal_substr($hex, 2, 2);
+    $b = drupal_substr($hex, 4, 2);
   }
 
   $r = hexdec($r);
@@ -1255,7 +1263,7 @@ function _textimage_hex2rgb($hex) {
  */
 function textimage_path($preset, $text, $additional_text = array(), $format = 'png') {
   $additional_text = array_reverse($additional_text);
-  $path = file_directory_path() . '/textimage/' . $preset . '/' . (empty($additional_text) ? '' : implode('/', $additional_text) . '/') . $text . '.' . $format;
+  $path = file_directory_path() .'/textimage/'. $preset .'/'. (empty($additional_text) ? '' : implode('/', $additional_text) .'/') . $text .'.'. $format;
   return drupal_urlencode(str_replace(' ', '_', $path));
 }
 
Only in 6.x-1.x-dev/: translations
