Ver Mensaje Individual
  #5 (permalink)  
Antiguo 27/10/2007, 12:38
Avatar de IMAC/
IMAC/
 
Fecha de Ingreso: octubre-2005
Mensajes: 738
Antigüedad: 18 años, 6 meses
Puntos: 14
Re: ini_set("memory_limit", "30M");

Lo saqué de un comentario de la página de php.net
No estoy seguro si lo estoy haciendo bien o no, pero me extraña que el fallo esté en la memoria...

Es algo tal que así:

Código PHP:
<?
ini_set
("memory_limit""30M");

//  Example of use...

//  This is a simple function to output text to an image
//  which is centered (as much as I want to do by eye)
//  and wrapped
//    Just remember that all the sizes are guessed
// doesn't cut on the space (only on number of characters)
//  or change color of text, but this isn't for that...
function imageCenterString$imgw$imgh,
   
$image_text ''$text_size=)
{
   
$im imagecreate$imgw$imgh );
   
   
// white background and blue text
   
$bg imagecolorallocate($im255255255);
   
$textcolor imagecolorallocate($im000);
   
   
$t_h $t_w $t_x $t_y 0;
   
$base_w =9$base_h 16;
   
$m 0.88;
   switch ( 
$text_size )
   {
      case 
1$t_w $base_w*pow(($m*.98),4);
         
$t_h $base_h*pow(($m*.98),4);
         break;
      case 
2$t_w $base_w*pow($m,3);
         
$t_h $base_h*pow($m,3);
         break;
      case 
3$t_w $base_w*pow($m,2);
         
$t_h $base_h*pow($m,2);
         break;
      case 
4$t_w $base_w*$m;
         
$t_h $base_h*$m;
         break;
      case 
5$t_w $base_w;
         
$t_h $base_h;
         break;
      default:
         if ( 
$text_size >= // set to 5
         
{   $t_w $base_w$t_h $base_h; }
         if ( 
$text_size // set to 1
         
{
            
$t_w $base_w*pow(($m*.98),4);
            
$t_h $base_h*pow(($m*.98),4);
         }
         break;
   }
   
   
$text_array = array();
   
   
$max floor($imgw/$t_w);
   
   for( 
$i=0strlen($image_text) > 0$i += $max)
   {
      
array_push($text_arraysubstr($image_text,0,$max));  // AQUÍ ME DA EL ERROR
      
if ( strlen($image_text) >= $max )
      {   
$image_text substr($image_text,$max); }
      else
      {   
$image_text 'no'; }
   }
   
   
$t_y = ($imgh/2) - ($t_h*count($text_array)/2);

   foreach ( 
$text_array as $text )
   {
      
$t_x = ($imgw/2)-($t_w*strlen($text)/2);
      
imagestring($im$text_size$t_x$t_y,
         
$text$textcolor);
      
$t_y += $t_h;
   }

   
// output the image
   
header("Content-type: image/gpeg");
   
imagejpeg($im);
}
imageCenterString(500,300,'hol'5);
?>