Print HTML tags in imagettftext PHP

0

I try to print HTML tags in the image I generate

<?php
// Establecer el tipo de contenido
header('Content-Type: image/png');

// Crear la imagen
-----------------
$im = imagecreatetruecolor(400, 30);

// Crear algunos colores
-----------------
$blanco = imagecolorallocate($im, 255, 255, 255);
$gris = imagecolorallocate($im, 128, 128, 128);
$negro = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $blanco);

// El texto a dibujar
-----------------
$texto = "< b > Testing...< /b>";
// Reemplace la ruta por la de su propia fuente
$fuente = 'arial.ttf';

// Añadir algo de sombra al texto
-----------------
imagettftext($im, 20, 0, 11, 21, $gris, $fuente, $texto);

// Añadir el texto
imagettftext($im, 20, 0, 10, 20, $negro, $fuente, $texto);

// Usar imagepng() resultará en un texto más claro comparado con imagejpeg()
imagepng($im);
imagedestroy($im);

In my code the html tags are printed < b > Testing ... < / b > I need to go in bold for example.

    
asked by Ronald 20.06.2017 в 01:23
source

1 answer

0

You can not format the text to insert in an image with HTML or CSS. You need to manipulate the text with imagettftext ; try this:

imagettftext($im, 20, 0, 10, 20, $negro, $fuente, $texto);
imagettftext($im, 20, 0, 10, 21, $negro, $fuente, $texto);
imagettftext($im, 20, 0, 11, 20, $negro, $fuente, $texto);

You can add more of these functions by adding pixels in X and Y until you're comfortable, always in increments of 1.

    
answered by 20.06.2017 в 05:59