| 1 | 2 | Manuela | //:Create an image from the textparameter
 | 
      
        | 2 |  |  | //:Use [[text2image?text=The text to create]]
 | 
      
        | 3 |  |  | //clean up old files..
 | 
      
        | 4 |  |  | $dir = WB_PATH.'/temp/';
 | 
      
        | 5 |  |  | $dp = opendir($dir) or die ('Could not open '.$dir);
 | 
      
        | 6 |  |  | while ($file = readdir($dp)) {
 | 
      
        | 7 |  |  | if ((preg_match('/img_/',$file)) && (filemtime($dir.$file)) <  (strtotime('-10 minutes'))) {
 | 
      
        | 8 |  |  | unlink($dir.$file);
 | 
      
        | 9 |  |  | }
 | 
      
        | 10 |  |  | }
 | 
      
        | 11 |  |  | closedir($dp);
 | 
      
        | 12 |  |  | $imgfilename = 'img_'.rand().'_'.time().'.jpg';
 | 
      
        | 13 |  |  | //create image
 | 
      
        | 14 |  |  | $padding = 0;
 | 
      
        | 15 |  |  | $font = 3;
 | 
      
        | 16 |  |  | $height = imagefontheight($font) + ($padding * 2);
 | 
      
        | 17 |  |  | $width = imagefontwidth($font) * strlen($text) + ($padding * 2);
 | 
      
        | 18 |  |  | $image_handle = imagecreatetruecolor($width, $height);
 | 
      
        | 19 |  |  | $text_color = imagecolorallocate($image_handle, 0, 0, 0);
 | 
      
        | 20 |  |  | $background_color = imagecolorallocate($image_handle, 255, 255, 255);
 | 
      
        | 21 |  |  | $bg_height = imagesy($image_handle);
 | 
      
        | 22 |  |  | $bg_width = imagesx($image_handle);
 | 
      
        | 23 |  |  | imagefilledrectangle($image_handle, 0, 0, $bg_width, $bg_height, $background_color);
 | 
      
        | 24 |  |  | imagestring($image_handle, $font, $padding, $padding, $text, $text_color);
 | 
      
        | 25 |  |  | imagejpeg($image_handle,WB_PATH.'/temp/'.$imgfilename,100);
 | 
      
        | 26 |  |  | imagedestroy($image_handle);
 | 
      
        | 27 |  |  | return '<img src="'.WB_URL.'/temp/'.$imgfilename.'" style="border:0px;margin:0px;padding:0px;vertical-align:middle;" />';
 |