I am making a code to generate image from text to the customer registry, for clients that did not upload image, be the initials of the name and surname as image, same as gmail, hotmail and so on. The problem is that we have $nome
that contains the person's full name, I can not get only the first letter of the 1st and 2nd names, for example, "Thomas Franklin" only "TH" and save as image in the bank and hosp. The image generation code I already have, but the part where you make the selection of the letters and save the image I can not.
Code:
<?php
class GerarAvatar {
function __construct()
{
$nome = $_GET['nome'];
$model = $_GET['model'];
$this->nome_para_avatar = $nome;
$this->mod_para_avatar = $model;
}
public function gerar()
{
header("Content-Type: image/jpeg");
$texto = $this->nome_para_avatar;
$mod_escolhido = $this->mod_para_avatar;
$add_extensao = '../imgs/' . $mod_escolhido . '.jpg';
$font_path = '../fonts/Poppins-Bold.ttf';
if ($mod_escolhido == 'vermelho') {
$modelo = imagecreatefromjpeg($add_extensao);
$bg_default = imagecolorallocate($modelo, 255, 255, 255);
imagettftext($modelo, 20, 0, 30, 55, $bg_default, $font_path, $texto);
}elseif ($mod_escolhido == 'azul') {
$modelo = imagecreatefromjpeg($add_extensao);
$bg_default = imagecolorallocate($modelo, 0, 0, 0);
imagettftext($modelo, 12, 0, 10, 200, $bg_default, $font_path, $texto);
}elseif($mod_escolhido !== 'vermelho'){
$modelo = imagecreatefromjpeg('../imgs/cinza.jpg');
$bg_default = imagecolorallocate($modelo, 255, 255, 255);
imagettftext($modelo, 20, 0, 30, 55, $bg_default, $font_path, $texto);
}
imagejpeg($modelo);
imagedestroy($modelo);
}
}
$gerar = new GerarAvatar();
$gerar->gerar();
?>