Problema con

  • HHawk
  • Novice
  • Novice
  • No Avatar
  • Registrado: Ago 13, 2009
  • Mensajes: 22
  • Status: Offline

Nota Junio 1st, 2010, 1:41 am

Bueno esto es lo que estoy tratando de hacer.

Estoy tratando de que PHP para crear un texto a la imagen. Sin embargo, estoy con un problema pequeño. El fondo me está matando. Desde que lo uso en una imagen (gradiente de color), un fondo de color 1 será hacer que se vea feo.

Hacer transparente el fondo, que funciona parcialmente, hace que sea todavía se ven feos.

Ahora me preguntaba si podría un png pre-hechos de fondo que se utilizaría por debajo del texto generado. ¿Es eso posible? En caso afirmativo cómo.

Así es como actualmente se ve y funciona. Quiero agregar un fondo a la misma.

Código: [ Select ]
<?php 
setlocale(LC_TIME, "nl_NL");

// Set the content-type 
header('Content-type: image/png'); 
 
// Create the image 
$im = imagecreatetruecolor(260, 20); 
 
// Create some colors 
$white = imagecolorallocate($im, 255, 255, 255); 
$grey = imagecolorallocate($im, 128, 128, 128); 
$black = imagecolorallocate($im, 0, 0, 0);
$custom = imagecolorallocate($im, 35, 38, 41);
imagefilledrectangle($im, 0, 0, 300, 20, $white);
 
// The text to draw 
#$text = "23 september 2010";

$text = strftime("%e %B'%y\n");
$text = strtoupper($text);

// Replace path by your own font path 
$font = 'ras.otf'; 
 
// Add some shadow to the text 
imagettftext($im, 14, 0, 1, 17, $grey, $font, $text);
imagettftext($im, 14, 0, 1, 19, $grey, $font, $text);
imagettftext($im, 14, 0, 0, 18, $grey, $font, $text);
imagettftext($im, 14, 0, 2, 18, $grey, $font, $text);
 
// Add the text 
imagettftext($im, 14, 0, 1, 18, $black, $font, $text); 
 
// Using imagepng() results in clearer text compared with imagejpeg() 
imagepng($im); 
imagedestroy($im); 
?>
  1. <?php 
  2. setlocale(LC_TIME, "nl_NL");
  3. // Set the content-type 
  4. header('Content-type: image/png'); 
  5.  
  6. // Create the image 
  7. $im = imagecreatetruecolor(260, 20); 
  8.  
  9. // Create some colors 
  10. $white = imagecolorallocate($im, 255, 255, 255); 
  11. $grey = imagecolorallocate($im, 128, 128, 128); 
  12. $black = imagecolorallocate($im, 0, 0, 0);
  13. $custom = imagecolorallocate($im, 35, 38, 41);
  14. imagefilledrectangle($im, 0, 0, 300, 20, $white);
  15.  
  16. // The text to draw 
  17. #$text = "23 september 2010";
  18. $text = strftime("%e %B'%y\n");
  19. $text = strtoupper($text);
  20. // Replace path by your own font path 
  21. $font = 'ras.otf'; 
  22.  
  23. // Add some shadow to the text 
  24. imagettftext($im, 14, 0, 1, 17, $grey, $font, $text);
  25. imagettftext($im, 14, 0, 1, 19, $grey, $font, $text);
  26. imagettftext($im, 14, 0, 0, 18, $grey, $font, $text);
  27. imagettftext($im, 14, 0, 2, 18, $grey, $font, $text);
  28.  
  29. // Add the text 
  30. imagettftext($im, 14, 0, 1, 18, $black, $font, $text); 
  31.  
  32. // Using imagepng() results in clearer text compared with imagejpeg() 
  33. imagepng($im); 
  34. imagedestroy($im); 
  35. ?>


Por eso quiero saber si yo podría agregar un fondo fijo, por background.png ejemplo, a este archivo creado.

La razón por la que estoy usando PHP para hacer que el texto, es que los navegadores no soportan plenamente sombras (especialmente IE). Si no hay solución para esto, tendrá que utilizar texto sin formato. Suspiro...

¿Puede alguien por favor muéstrame cómo puedo añadir una imagen de fondo para el texto generado la imagen? Si su posible? Me falta el conocimiento de PHP para hacerlo yo mismo.

Gracias de antemano!
  • Anonymous
  • Bot
  • No Avatar
  • Registrado: 25 Feb 2008
  • Mensajes: ?
  • Loc: Ozzuland
  • Status: Online

Nota Junio 1st, 2010, 1:41 am

  • PaulR
  • Newbie
  • Newbie
  • No Avatar
  • Registrado: Jul 10, 2010
  • Mensajes: 5
  • Status: Offline

Nota Julio 24th, 2010, 10:46 pm

Mira debajo del código, es una simple imagen de fondo que he creado después subido a mi servidor.
Basta con sustituir http://www.ozzu.com con www (dot) pulso-box (dot) com y el ejemplo funcionará prefectamenta.

PHP Código: [ Select ]
header("Content-type: image/png");                               // Set the correct header type, edit accordingly.
$imageURL = 'http://www.ozzu.com/downloads/background.png'; // Define the image URL, I have used a default one from my server.
$im = imagecreatefrompng($imageURL)              // Create the image from the pre-defined URL
    or die("Cannot Initialize new GD image stream");             // Throw error if unable to initialize image stream            
imagealphablending($im, false);                                  // Alpha image blending
imagesavealpha($im, true);                                       // Save the Alpha blending
             
list($iWidth, $iHeight, $iType) = getimagesize($imageURL);       // Get width, height and image type, can be used later on
 
$black = imagecolorallocate($im, 0, 0, 0);  
$grey = imagecolorallocate($im, 50, 50, 50);                     // Set the text color: Black
$white = imagecolorallocate($im, 255, 255, 255);                 // Set the text color: White
 
imagestring($im, 2, 5, 5, "Some Text Here",  $white);            // Create the text and write it to the image
imagestring($im, 2, 5, 20, "Some Text Here", $grey);             // Create the text and write it to the image
imagestring($im, 2, 5, 35, "Some Text Here", $black);            // Create the text and write it to the image
imagepng($im);
imagedestroy($im);
 
  1. header("Content-type: image/png");                               // Set the correct header type, edit accordingly.
  2. $imageURL = 'http://www.ozzu.com/downloads/background.png'; // Define the image URL, I have used a default one from my server.
  3. $im = imagecreatefrompng($imageURL)              // Create the image from the pre-defined URL
  4.     or die("Cannot Initialize new GD image stream");             // Throw error if unable to initialize image stream            
  5. imagealphablending($im, false);                                  // Alpha image blending
  6. imagesavealpha($im, true);                                       // Save the Alpha blending
  7.              
  8. list($iWidth, $iHeight, $iType) = getimagesize($imageURL);       // Get width, height and image type, can be used later on
  9.  
  10. $black = imagecolorallocate($im, 0, 0, 0);  
  11. $grey = imagecolorallocate($im, 50, 50, 50);                     // Set the text color: Black
  12. $white = imagecolorallocate($im, 255, 255, 255);                 // Set the text color: White
  13.  
  14. imagestring($im, 2, 5, 5, "Some Text Here",  $white);            // Create the text and write it to the image
  15. imagestring($im, 2, 5, 20, "Some Text Here", $grey);             // Create the text and write it to the image
  16. imagestring($im, 2, 5, 35, "Some Text Here", $black);            // Create the text and write it to the image
  17. imagepng($im);
  18. imagedestroy($im);
  19.  



Todo lo que usted realmente tiene que cambiar con su guión se cambie la línea siguiente:
PHP Código: [ Select ]
$im = imagecreatetruecolor(260, 20)

Para el texto siguiente:
PHP Código: [ Select ]
$im = imagecreatefrompng($imageURL)

y debería funcionar, pero Im no seguro al 100% ya que no puede obtener su secuencia de comandos funciona correctamente gif "alt =": roll: "title =" Ojos del balanceo ">

Juega un poco con los dos guiones ver si puede hacerlo funcionar, si no me puede dar un PM 8)
Gracias, PaulR.

Publicar Información

  • Total de mensajes en este tema: 2 mensajes
  • Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 357 invitados
  • No puede abrir nuevos temas en este Foro
  • No puede responder a temas en este Foro
  • No puede editar sus mensajes en este Foro
  • No puede borrar sus mensajes en este Foro
  • No puede enviar adjuntos en este Foro
 
 

© 2011 Unmelted, LLC. Ozzu® es una marca registrada de Unmelted, LLC