Foros del Web » Programando para Internet » PHP »

Dibujar texto con transparencia

Estas en el tema de Dibujar texto con transparencia en el foro de PHP en Foros del Web. Hola ^^ Mi duda es cómo dibujar texto utilizando una fuente ttf en una imagen, pero que este texto tenga transparencia, alpha, y que se ...
  #1 (permalink)  
Antiguo 27/07/2007, 22:30
Avatar de geq
geq
 
Fecha de Ingreso: agosto-2006
Ubicación: Rosario
Mensajes: 655
Antigüedad: 17 años, 8 meses
Puntos: 22
Pregunta Dibujar texto con transparencia

Hola ^^

Mi duda es cómo dibujar texto utilizando una fuente ttf en una imagen, pero que este texto tenga transparencia, alpha, y que se superponga con el resto del contenido de la imagen.

Gracias.
Exitos.
  #2 (permalink)  
Antiguo 28/07/2007, 00:00
Avatar de DvD AdN  
Fecha de Ingreso: mayo-2005
Ubicación: Frente al monitor
Mensajes: 610
Antigüedad: 18 años, 11 meses
Puntos: 0
Re: Dibujar texto con transparencia

Eso se llama marca de agua, buscalo en los foros, se ha tratado el tema en muchos posts, checa este http://www.forosdelweb.com/showthrea...ght=marca+agua

Suerte
__________________
Keep f***ing learning
Ask for f***ing help.
Use f***ing spell check.
Think about all the f***ing possibilities.
  #3 (permalink)  
Antiguo 28/07/2007, 11:23
Avatar de geq
geq
 
Fecha de Ingreso: agosto-2006
Ubicación: Rosario
Mensajes: 655
Antigüedad: 17 años, 8 meses
Puntos: 22
Re: Dibujar texto con transparencia

Gracias ^^ He logrado esto:
Código PHP:
header("Content-type: image/jpeg");
    
    
$img imagecreatetruecolor(500,400);

    
$bbox imagettfbboxextended(50,0,"ttf/Trebuchet MS.ttf","g a b o..");
    
$timg imagecreatetruecolor($bbox["width"],$bbox["height"]);
    
$bgcolor imagecolorallocate($timg,255,255,255);
    
imagefill($timg,0,0,$bgcolor);
    
$txtcolor=imagecolorallocatealpha($timg,0,0,0,90);
    
imagettftext($timg,50,0,$bbox["x"],$bbox["y"],$txtcolor,"ttf/Trebuchet MS.ttf","g a b o..");
    
imagealphablending($img,true);
    
$bgcolor imagecolorallocate($img,255,255,255);
    
imagefill($img,0,0,$bgcolor);
    
imagecopy($img,$timg,50,50,0,0,$bbox["width"],$bbox["height"]);
    
imagejpeg($img,"",100); 
imagettfbboxextended():
Código PHP:
function imagettfbboxextended($size$angle$fontfile$text) {
    
/*this function extends imagettfbbox and includes within the returned array
    the actual text width and height as well as the x and y coordinates the 
    text should be drawn from to render correctly.  This currently only works
    for an angle of zero and corrects the issue of hanging letters e.g. jpqg*/
    
$bbox imagettfbbox($size$angle$fontfile$text);

    
//calculate x baseline
    
if($bbox[0] >= -1) {
        
$bbox['x'] = abs($bbox[0] + 1) * -1;
    } else {
        
//$bbox['x'] = 0;
        
$bbox['x'] = abs($bbox[0] + 2);
    }

    
//calculate actual text width
    
$bbox['width'] = abs($bbox[2] - $bbox[0]);
    if(
$bbox[0] < -1) {
        
$bbox['width'] = abs($bbox[2]) + abs($bbox[0]) - 1;
    }

    
//calculate y baseline
    
$bbox['y'] = abs($bbox[5] + 1);

    
//calculate actual text height
    
$bbox['height'] = abs($bbox[7]) - abs($bbox[1]);
    if(
$bbox[3] > 0) {
        
$bbox['height'] = abs($bbox[7] - $bbox[1]) - 1;
    }

    return 
$bbox;

Extraída de php.net

Gracias ^^
Exitos.
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 21:40.