0
I am making a code to generate image from text for client registration, for clients who did not upload image, was the initials of the name and surname as image, equal to gmail, Hotmail and etc. The problem is that, we have the $nome
which contains the full name of the person, I am not able to take only the first letter of the first and second name, for example, "Thomas Franklin" take only "TH" and save as image in the bank and Hosp. The image generation code I already have, but the part where you select the letters and save the image I’m not getting.
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();
?>
Could you give me an example?
– Thomas Franklin