Index: textimage.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/textimage/textimage.module,v
retrieving revision 1.14
diff -r1.14 textimage.module
331a332,340
>   $form['settings']['text']['max_width'] = array(
>     '#type' => 'textfield',
>     '#title' => t('Max width'),
>     '#field_suffix' => t('pixels'),
>     '#description' => t('Max text width, this includes the margin. Leave blank to disable wrapping.'),
>     '#default_value' => $preset['settings']['text']['max_width'],
>     '#maxlength' => 4,
>     '#size' => 4,
>   );
651a661
>   $max_width = $preset['settings']['text']['max_width'];
657c667
<   
---
> 
694c704
<   $img = textimage_text_to_image($text, $size, $font, $color, $back_color, $angle);
---
>   $img = textimage_text_to_image($text, $size, $font, $color, $back_color, $angle, $max_width-$margin_right-$margin_left);
867c877,915
< function textimage_text_to_image($text, $fontsize, $font, $foreground_color = '#000000', $background_color = NULL, $angle) {
---
> function textimage_text_wrap($text, $fontsize, $font, $angle, $max_width) {
>   $lines[0] = explode(" ",$text);
>   $ih = 0;
>   $c = 1;
>   
>   do {
>     // Get exact dimensions of text string
>     $box = imageTTFBbox($fontsize, $angle, $font, implode($lines[$c-1]," "));
>     // Calculate text width and height
>     $iw = abs($box[4] - $box[0]) + 4;
>     $ih = abs($box[5] - $box[1]) + 4;
>     
>     if(($max_width > 0) && ($iw > $max_width)) {
>       if(!isset($lines[$c]))
>         $lines[$c] = array();
>       if(count($lines[$c-1]) > 1) {
>         array_unshift($lines[$c],array_pop($lines[$c-1]));
>         continue;
>       }
>     }
>     
>     $c++;
>     
>   } while(count($lines) >= $c);
>   
>   
>   $wrapped_text = '';
>   foreach($lines as $line) {
>     $wrapped_text .= implode($line," ")."\n";
>   }
>   
>   return $wrapped_text;
> }
> 
> function textimage_text_to_image($text, $fontsize, $font, $foreground_color = '#000000', $background_color = NULL, $angle, $max_width) {
> 
>   if($max_width)
>     $text = textimage_text_wrap($text, $fontsize, $font, $angle, $max_width);
>   

