This commit is contained in:
2025-01-19 17:15:58 +03:00
parent 40369fb515
commit b18378bcb1
41 changed files with 1257 additions and 30 deletions

View File

@ -8,6 +8,7 @@ use DragonCode\CardNumber\Formatters\BankFormatter;
use kernel\app_modules\card\models\Card;
use kernel\app_modules\card\models\CardFile;
use kernel\FormModel;
use kernel\helpers\Debug;
use kernel\helpers\ImageGD;
use Endroid\QrCode\Color\Color;
use Endroid\QrCode\Encoding\Encoding;
@ -68,22 +69,45 @@ class CardFileService
umask($oldMask);
$uploadFileDir = ROOT_DIR . $uploadDirUri;
$img = ROOT_DIR . "/" . $card->cardTemplate->path; // Ссылка на файл
$font = RESOURCES_DIR . "/arialmt.ttf"; // Ссылка на шрифт
$cardSettings = json_decode($card->cardTemplate->settings ?? "", true);
$qr = self::createQr($card->id);
$img = ROOT_DIR . "/" . $card->cardTemplate->path; // Ссылка на файл
$font = RESOURCES_DIR . "/Montserrat-SemiBold.ttf"; // Ссылка на шрифт
$qr = self::createQr($card->id, $cardSettings['qr_size'] ?? 131);
$qrImg = new ImageGD($qr->getDataUri());
$img = new ImageGD($img);
$pngFilePath = RESOURCES_DIR . "/tmp/" . $card->id . ".png";
$pngFileUrl = "/resources/tmp/" . $card->id . ".png";
$img->addText(font_size: 14, degree: 0, x: 15, y: 25, color: "#000000", font: $font, text: "KO coin");
$img->addText(font_size: 14, degree: 0, x: 15, y: 45, color: "#000000", font: $font, text: "BGroup\ITGuild");
$img->addText(font_size: 14, degree: 0, x: 15, y: 65, color: "#000000", font: $font, text: $card->cardTemplate->title . " card");
$img->addText(font_size: 18, degree: 0, x: 15, y: 180, color: "#000000", font: $font, text: $cardNumber);
$img->addText(font_size: 12, degree: 0, x: 15, y: 200, color: "#000000", font: $font, text: $card->username);
$img->addImg($qrImg->getImg(), 200, 15, 0, 0, 124, 124, 100);
$img->addText(
font_size: 20,
degree: 0,
x: 15,
y: 190,
color: $cardSettings['card_number_color'] ?? "#ffffff",
font: $font,
text: $cardNumber
);
$img->addText(
font_size: 12,
degree: 0,
x: 15,
y: 210,
color: $cardSettings['card_name_color'] ?? "#FEE62F",
font: $font,
text: $card->username
);
$img->addImg($qrImg->getImg(),
$cardSettings['qr_location_x'] ?? 190,
$cardSettings['qr_location_y'] ?? 20,
0,
0,
$cardSettings['qr_box_width'] ?? 135,
$cardSettings['qr_box_height'] ?? 135,
100
);
$img->save($uploadFileDir . $newFileName);
return $uploadDirUri . $newFileName;
@ -92,7 +116,7 @@ class CardFileService
return false;
}
public static function createQr(string|int $text): \Endroid\QrCode\Writer\Result\ResultInterface
public static function createQr(string|int $text, int $size = 131): \Endroid\QrCode\Writer\Result\ResultInterface
{
$writer = new PngWriter();
@ -100,7 +124,7 @@ class CardFileService
data: $text,
encoding: new Encoding('UTF-8'),
errorCorrectionLevel: ErrorCorrectionLevel::Low,
size: 120,
size: $size,
margin: 2,
roundBlockSizeMode: RoundBlockSizeMode::Margin,
foregroundColor: new Color(0, 0, 0),