51 lines
1.4 KiB
PHP
51 lines
1.4 KiB
PHP
|
<?php
|
||
|
require_once __DIR__ . '/vendor/autoload.php';
|
||
|
|
||
|
use Imagine\Gd\Font;
|
||
|
use Imagine\Gd\Imagine;
|
||
|
use Imagine\Image\Palette\RGB;
|
||
|
use Imagine\Image\Point;
|
||
|
|
||
|
$templatesDirectory = __DIR__ . '/templates';
|
||
|
$validFiles = [
|
||
|
'diplom-1.png' => [
|
||
|
'positions' => [
|
||
|
'top' => ['x' => 125, 'y' => 270, 'maxWidth' => 262],
|
||
|
'bottom' => ['x' => 150, 'y' => 350, 'maxWidth' => 216],
|
||
|
],
|
||
|
],
|
||
|
];
|
||
|
|
||
|
$template = $_GET['template'] ?? '';
|
||
|
$topText = $_GET['top'] ?? '';
|
||
|
$bottomText = $_GET['bottom'] ?? '';
|
||
|
|
||
|
if (!isset($validFiles[$template]) || !file_exists(sprintf('%s/%s', $templatesDirectory, $template))) {
|
||
|
die('Invalid template');
|
||
|
}
|
||
|
|
||
|
if (empty($topText) || empty($bottomText)) {
|
||
|
die('Invalid text');
|
||
|
}
|
||
|
|
||
|
$templateFile = sprintf('%s/%s', $templatesDirectory, $template);
|
||
|
$positions = $validFiles[$template]['positions'];
|
||
|
$imagine = new Imagine();
|
||
|
|
||
|
$palette = new RGB();
|
||
|
$colorBlack = $palette->color('#000000', 100);
|
||
|
|
||
|
$image = $imagine->open($templateFile);
|
||
|
|
||
|
$font = new Font($_ENV['FONT_LOCATION'], 12, $colorBlack);
|
||
|
|
||
|
$top = $positions['top'];
|
||
|
$bottom = $positions['bottom'];
|
||
|
$topPosition = new Point($top['x'], $top['y']);
|
||
|
$bottomPosition = new Point($bottom['x'], $bottom['y']);
|
||
|
|
||
|
$image->draw()->text($topText, $font, $topPosition, 0, $top['maxWidth'] ?? null);
|
||
|
$image->draw()->text($bottomText, $font, $bottomPosition, 0, $bottom['maxWidth'] ?? null);
|
||
|
|
||
|
$image->show('png');
|