Hello friends today I was born a question after looking for a way to create images in php I have just achieved a basic form.
<?php
// Establecer el tipo de contenido
header('Content-Type: image/png');
// Crear la imagen
$im = imagecreatetruecolor(400, 400);
// 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, 400, 400, $gris);
// El texto a dibujar
$texto = 'Convertir texto a imagen con PHP';
// Reemplace la ruta por la de su propia fuente
$fuente = 'Galpon-Black.otf';
// Añadir algo de sombra al texto
imagettftext($im, 20, 0, 11, 21, $gris, $fuente, $texto);
// Añadir el texto
imagettftext($im, 20, 0, 150, 200, $negro, $fuente, $texto);
// Usar imagepng() resultará en un texto más claro comparado con imagejpeg()
imagepng($im);
imagedestroy($im);
?>
If you execute this code, create the image and add the text, but if the text is too long, leave it out of the image in a few words. What I'm looking for is that the text, regardless of the size, fits the center of the image.