Foros del Web » Programando para Internet » PHP »

write text to transparent image

Estas en el tema de write text to transparent image en el foro de PHP en Foros del Web. Does anybody know why this code is only working locally on xampp but not on remote server where I just see a black rectangle instead ...
  #1 (permalink)  
Antiguo 14/12/2009, 14:09
Avatar de thosecars82  
Fecha de Ingreso: abril-2008
Mensajes: 32
Antigüedad: 16 años
Puntos: 0
write text to transparent image

Does anybody know why this code is only working locally on xampp but not on remote server where I just see a black rectangle instead of the word "phone"?
You can check it at [url]http://www.arreglaordenador.com/numberimage4.php[/url]

Código:
<?php
 $fontDir = $rootPath . "fonts\\";
header("Content-type: image/png"); //Picture Format
header("Expires: Mon, 01 Jul 2003 00:00:00 GMT"); // Past date
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // Consitnuously modified
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Pragma: no-cache"); // NO CACHE

/*image generation code*/
//create Image of size 350px x 75px
$bg = imagecreatetruecolor(350, 75);

//This will make it transparent
imagesavealpha($bg, true);

$trans_colour = imagecolorallocatealpha($bg, 0, 0, 0, 127);
imagefill($bg, 0, 0, $trans_colour);

//Text to be written
$helloworld = isset($_GET['text']) ? $_GET['text'] : "phone";

// White text
$white = imagecolorallocate($bg, 255, 255, 255);
// Grey Text
$grey = imagecolorallocate($bg, 128, 128, 128);
// Black Text
$black = imagecolorallocate($bg, 0,0,0);

$font = 'arial.ttf'; //path to font you want to use
$fontsize = 20; //size of font

//Writes text to the image using fonts using FreeType 2
imagettftext($bg, $fontsize, 0, 20, 20, $grey, $fontDir.$font, $helloworld);

//Create image
imagepng($bg);

//destroy image
ImageDestroy($bg);
?>
Thank you very much.
  #2 (permalink)  
Antiguo 14/12/2009, 14:16
Avatar de blogger  
Fecha de Ingreso: diciembre-2005
Ubicación: frente al monitor
Mensajes: 398
Antigüedad: 18 años, 4 meses
Puntos: 12
Respuesta: write text to transparent image

not really sure, but could it be that the path for the font is not correct? other than that I see no problem homes...
__________________
http://exegesis-biblica.com/
  #3 (permalink)  
Antiguo 14/12/2009, 14:26
Avatar de thosecars82  
Fecha de Ingreso: abril-2008
Mensajes: 32
Antigüedad: 16 años
Puntos: 0
Respuesta: write text to transparent image

Cita:
Iniciado por blogger Ver Mensaje
not really sure, but could it be that the path for the font is not correct? other than that I see no problem homes...
Se que ese no es el problema porque las fuentes están subidas al servidor remoto.
En local funciona perfectamente, pero es como si en remoto no funcionara la transparencia por algún motivo que desconozco.
  #4 (permalink)  
Antiguo 14/12/2009, 14:56
Avatar de jackson666  
Fecha de Ingreso: noviembre-2009
Ubicación: Buenos Aires, Argentina
Mensajes: 1.971
Antigüedad: 14 años, 5 meses
Puntos: 65
Respuesta: write text to transparent image

Cita:
Iniciado por thosecars82 Ver Mensaje
Se que ese no es el problema porque las fuentes están subidas al servidor remoto.
En local funciona perfectamente, pero es como si en remoto no funcionara la transparencia por algún motivo que desconozco.
Para que preguntas en ingles, sabiendo que la mayoria de este foro son de habla hispana?
  #5 (permalink)  
Antiguo 14/12/2009, 15:05
Avatar de thosecars82  
Fecha de Ingreso: abril-2008
Mensajes: 32
Antigüedad: 16 años
Puntos: 0
Respuesta: write text to transparent image

Cita:
Iniciado por jackson666 Ver Mensaje
Para que preguntas en ingles, sabiendo que la mayoria de este foro son de habla hispana?
Discúlpame que no me he dado cuenta.
Mira ya que no veo donde está el problema para intentar simplificar el código lo he dejado así:

Código:
<?php
header("Content-type: image/png"); //Picture Format
$bg = imagecreatetruecolor(350, 75);

//This will make it transparent
imagesavealpha($bg, true);

$trans_colour = imagecolorallocatealpha($bg, 0, 0, 0, 127);
imagefill($bg, 0, 0, $trans_colour);


//Create image
imagepng($bg);

//destroy image
ImageDestroy($bg);
?>
De esta manera no se debería mostrar nada pues el rectángulo negro en un principio se habría convertido en transparente con
las líneas
Código:
//This will make it transparent
imagesavealpha($bg, true);

$trans_colour = imagecolorallocatealpha($bg, 0, 0, 0, 127);
imagefill($bg, 0, 0, $trans_colour);
sin embargo sigue ocurriendo que cuando lo ejecuto en remoto (www.arreglaordenador.com/numberimage4.php) se ve el rectángulo en negro como si no funcionara la transparencia y cuando lo ejecuto en local, el rectángulo no se ve tal y como era de esperar pues he puesto las dos líneas de código para hacer el rectángulo transparente.

¿a alguien se le ocurre alguna idea sobre por qué no funciona la transparencia en el servidor remoto pero sí en el local?
El phpinfo() del servidor remoto me muestra los siguientes ajustes para GD library:

Configure Command
'./configure' '--prefix=/usr/local/php5' '--with-mysql=/usr' '--with-gd' '--with-gzip' '--with-zlib' '--with-kerberos' '--enable-ftp' '--enable-gd-native-ttf' '--with-freetype-dir=/usr' '--with-jpeg-dir=/usr' '--with-xpm-dir=/usr' '--with-png-dir=/usr' '--with-imagick' '--enable-bcmath' '--with-xml' '--with-dom' '--with-gettext' '--enable-mbstring' '--with-curl' '--with-imap' '--enable-calendar' '--enable-mhash' '--enable-openssl' '--with-openssl=/usr' '--enable-exif' '--with-mhash=/usr' '--enable-mcrypt' '--with-mcrypt=/usr' '--with-imap-ssl' '--enable-xslt' '--with-dom-xslt=/usr' '--with-xslt-sablot=/usr' '--with-config-file-path=/home/sys/php5' '--with-pgsql=/usr' '--with-pdo-mysql' '--with-pdo-pgqsl' '--with-mysqli' '--with-pear' '--with-iconv' '--with-xsl=/usr' '--enable-fastcgi'

Código:
GD Support  enabled  
GD Version  bundled (2.0.34 compatible)  
FreeType Support  enabled  
FreeType Linkage  with freetype  
FreeType Version  2.1.7  
GIF Read Support  enabled  
GIF Create Support  enabled  
JPG Support  enabled  
PNG Support  enabled  
WBMP Support  enabled  
XPM Support  enabled  
XBM Support  enabled
Agradezco cualquier idea para que funcione la transparencia en el servidor remoto.
Muchas gracias.

Última edición por thosecars82; 05/04/2011 a las 15:24
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 16:47.