<?php
declare(strict_types=1);

$fontBytes = base64_decode(file_get_contents("fixture-font.base64"), true);
file_put_contents("fixture.ttf", $fontBytes);
$font = __DIR__ . "/fixture.ttf";
$image = imagecreatetruecolor(240, 70);
$white = imagecolorallocate($image, 255, 255, 255);
$box = imageftbbox(18.0, 0.0, $font, "Чашка");
$left = min($box[0], $box[2], $box[4], $box[6]);
$right = max($box[0], $box[2], $box[4], $box[6]);
$x = (int) floor((imagesx($image) - ($right - $left)) / 2 - $left);
imagettftext($image, 18.0, 0.0, $x, 44, $white, $font, "Чашка");
echo $x > 0 ? "centered with margin\n" : "too wide\n";
