<?php
declare(strict_types=1);

$theme = $_GET["theme"] ?? "blue";
$label = $_GET["label"] ?? "NEW";
$radius = $_GET["radius"] ?? "18";
if (!is_string($theme) || !in_array($theme, ["blue", "clay"], true)
    || !is_string($label) || !in_array($label, ["NEW", "SALE"], true)
    || !is_string($radius) || !in_array($radius, ["18", "28"], true)) {
    http_response_code(400);
    header("Content-Type: text/plain; charset=utf-8");
    echo "Choose a listed theme, label and radius.\n";
    exit;
}
$rgb = $theme === "blue" ? [25, 105, 175] : [160, 65, 40];
$radius = (int) $radius;
$image = imagecreatetruecolor(240, 100);
$background = imagecolorallocate($image, $rgb[0], $rgb[1], $rgb[2]);
$white = imagecolorallocate($image, 255, 255, 255);
$accent = imagecolorallocate($image, 255, 210, 75);
imagefill($image, 0, 0, $background);
imagefilledellipse($image, 195, 50, $radius * 2, $radius * 2, $accent);
imagestring($image, 5, 20, 42, $label, $white);
header("Content-Type: image/png");
imagepng($image);
