<?php
$tempDir = "./temp/";

if(isSet($_GET['text']) && isSet($_GET['size'])){
  $text = $_GET['text'];
  $size = $_GET['size'];
  if($text == "" || !is_numeric($size)){
    die("error\nNieprawidłowe dane.");
  }

  $font = "arial.ttf";

  $arr = imagettfbbox($size, 0, $font, $text);
  $width = abs($arr[2] - $arr[0]) + 5;
  $height = abs($arr[1] - $arr[7]) + 1;
  $img = imagecreatetruecolor($width, $height);
  $white = imagecolorallocate($img, 255, 255, 255);
  $black = imagecolorallocate($img, 0, 0, 0);

  imagefill($img, 0, 0, $white);
  imagettftext($img, $size, 0, 0, $height, $black, $font, $text);

  $imgName = microtime().rand();
  imagejpeg($img, $tempDir.$imgName);
  imagedestroy($img);
  echo $imgName;
}
else{
  die("error\nNieprawidłowe dane.");
}
?>