<?php

function createImg($text, $sender) {
    $width = 600;
    $height = 300;
    $image = imagecreatetruecolor($width, $height);

    $backgroundColor = imagecolorallocate($image, 200, 200, 200);
    imagefill($image, 0, 0, $backgroundColor);
    $textColor = imagecolorallocate($image, 0, 0, 0);
    $font = 5; 
    $fontSize = 40;
    
    $dateTime = DateTime::createFromFormat('YmdHis', $text);

    if ($dateTime !== false) {
        $imageText = $dateTime->format('Y-m-d H:i:s');
        $saveText = $text;
    } else {
        $saveText = str_replace(' ', '', $text);
        $imageText = $text;
    }

    $fontHeight = imagefontheight($font);
    $textWidth = imagefontwidth($font) * strlen($imageText);
    $textHeight = $fontHeight;
    $textX = ($width - $textWidth) / 2;
    $textY = ($height - $textHeight) / 2;


    imagestring($image, $font, $textX, $textY, $imageText, $textColor);

    $outputPath = 'images/' . $sender . "_" . $saveText . '.jpg'; 
    imagejpeg($image, $outputPath);
    imagedestroy($image);
}

?>
