Foros del Web » Programando para Internet » PHP »

imagenes en PHP!!

Estas en el tema de imagenes en PHP!! en el foro de PHP en Foros del Web. Estoy haciendo una imagen en PHP que es solamente un fondo y texto... cuando pongo: $text="TEXTO TEXTO TEXTO TEXTO TEXTO TEXTO TEXTO \n TEXTO TEXTO ...
  #1 (permalink)  
Antiguo 12/02/2005, 02:47
 
Fecha de Ingreso: noviembre-2004
Mensajes: 68
Antigüedad: 19 años, 5 meses
Puntos: 0
imagenes en PHP!!

Estoy haciendo una imagen en PHP que es solamente un fondo y texto...

cuando pongo:

$text="TEXTO TEXTO TEXTO TEXTO TEXTO TEXTO TEXTO \n TEXTO TEXTO TEXTO TEXTO TEXTO TEXTO TEXTO TEXTO TEXTO TEXTO TEXTO TEXTO TEXTO TEXTO TEXTO TEXTO TEXTO TEXTO TEXTO TEXTO \n";

quiero que cuando alla un \n salga un salto de linea, pero me sale solo unos simbolos raros...

tambien otra cosa... tengo una imagen de 200x300
como puedo hacer que el TEXTO quede ajustado en esa imagen??... si tengo otro texto se adapte...

ejemplo: tengo esta imagen:

|-------------------------|
| |
| |
| |
| |
| |
|-------------------------|

y tengo el siguiente texto:

El mejor Foro: Foros del Web

salgan:

|-------------------------|
| |
| El mejor Foro: Foros del |
| Web |
| |
| |
|-------------------------|

si necesidad de poner:

El mejor Foro: Foros del \n Web


espero que entiendan... saludos
  #2 (permalink)  
Antiguo 12/02/2005, 04:24
 
Fecha de Ingreso: febrero-2005
Mensajes: 396
Antigüedad: 19 años, 2 meses
Puntos: 1
Creo que el que pregunta lo está haciendo para usarlo con la funcion de pintar una cadena dentro de una imagen, no con HTML.

La idea es que no hay una función que lo haga directamente. Yo en su día tenia que hacer algo parecido y creé una función para hacer eso. De hecho te la paso más abajo. Como podrás ver la función no solo te permite hacer lo que tu quieres, sino que además permite que las letras tengan una "sombrita". Por otro lado, también permite mezclar dos tipos de letra distintos (originalmente era para poder meter negrita, pero si en vez de pasar como parametro "fontBoldName" la fuente en negrita pones otro tipo de letra funcionará bien. La función básicamente lo que hace es ir comprobando la longitud de la línea si añades una nueva palabra, y si te pasas del ancho que se especifica supone que tiene uqe hacer un salto de línea. Espero que te sea útil.

Un saludo

Zerjillo

Código PHP:
/*
Extended version of the previous funtion. It allows to print multiple line text horizontally centered around a certain coordinate. It can mix regular / bold style. The text in double brackets [[...]] will be printed in bold text.

Parameters:
  $image: The image where the string will be printed
  $string: The string to be printed
  $x: The text will be horizontally centered on this coordinate
  $y: Vertical coordinate for the first line of the text
  $maxWidth: Maximum with for a line (in pixels)
  $lineHeight: Line height (kinda space between lines)
  $fontName: Name of the "regular" font
  $fontBoldName: Name of the "bold" font
  $fontSize: The font size
  $color: The color of the printed message
  $shadowColor: The color for the shadow of the message

*/

function drawStringWithShadow2($image$string$x$y$maxWidth$lineHeight$fontName$fontBoldName$fontSize$color$shadowColor) {

  
$currentFont $fontName;

// Tokenizig message words
  
$words explode(" "$string);
  for (
$i $i count($words) ; $i++) {
    
$words[$i] = $words[$i] . " ";
  }

  
$currentFont $fontName;
  
$firstWordOfLine 0;
  
$lastWordOfLine 0;
  
$actualWidth 0;
  
$wordSize 0;

  
$initLineFont $fontName;

// While there are words to be printed
  
while ($lastWordOfLine count($words)) {

// Compute line width

    
while ( ($actualWidth $wordSize $maxWidth) && ($lastWordOfLine count($words)) ) {
      
$actualWidth += $wordSize;
      
$currentWord $words[$lastWordOfLine];

// If we must change the font into a bold one
      
if (strcmp(substr($currentWord02), "[[") == 0) {
        
$currentWord substr($currentWord2);
        
$currentFont $fontBoldName;
      }

// If bold font ends
      
$changeFontToOriginal false;
      if (
strcmp(substr($currentWordstrlen($currentWord) - 3), "]] ") == 0) {
        
$currentWord substr($currentWord0strlen($currentWord) - 3) . " ";
        
$changeFontToOriginal true;
      }

// Calculate word width
      
list($lx,$ly,$rx,$ry) = imagettfbbox($fontSize0$currentFont$currentWord);
      
$wordSize $rx $lx;
      
$lastWordOfLine++;

      if (
$changeFontToOriginal) {
        
$currentFont $fontName;
      }
    }

// Readjusting last word of line (if neccesary)
    
if ($lastWordOfLine != count($words)) {
      
$lastWordOfLine--;
    } else {
      
$actualWidth += $wordSize;
    }

// Begin printing line
    
$currentFont $initLineFont;
    
$xx $x $actualWidth 2;  // Initial horizontal coordinate

    
for ($i $firstWordOfLine $i $lastWordOfLine $i++) {
      
$currentWord $words[$i];

// If we must change the font into a bold one
      
if (strcmp(substr($currentWord02), "[[") == 0) {
        
$currentWord substr($currentWord2);
        
$currentFont $fontBoldName;
      }

// If bold font ends
      
$changeFontToOriginal false;
      if (
strcmp(substr($currentWordstrlen($currentWord) - 3), "]] ") == 0) {
        
$currentWord substr($currentWord0strlen($currentWord) - 3) . " ";
        
$changeFontToOriginal true;
      }

      list(
$lx,$ly,$rx,$ry) = imagettfbbox($fontSize0$currentFont$currentWord);
      
$wordSize $rx $lx;

// Print word
      
imagettftext($image$fontSize0$xx 3$y 3$shadowColor$currentFont$currentWord);
      
imagettftext($image$fontSize0$xx$y$color$currentFont$currentWord);
      
$xx += $wordSize;

      if (
$changeFontToOriginal) {
        
$currentFont $fontName;
      }
    }

    
$y += $lineHeight;  // Next line
    
$firstWordOfLine $lastWordOfLine;
    
$actualWidth 0;
    
$wordSize 0;
    
$initLineFont $currentFont;  // save current font
  
}

  #3 (permalink)  
Antiguo 12/02/2005, 23:52
 
Fecha de Ingreso: noviembre-2004
Mensajes: 68
Antigüedad: 19 años, 5 meses
Puntos: 0
me podrias dar un ejemplo de como soltar esa funcion, me sale error...
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 02:54.