imageManager->createImage($config->getWidth(), $config->getHeight()); $image->insertBackground($config->randomBackground()); $image = match ($symbols->getType()) { SymbolType::String => $this->processingString($image, $symbols, $config), }; if ($config->getNumberLines() > 0) { $this->imageLines->processing(image: $image, colors: $config->getLineColors(), lines: $config->getNumberLines()); } $image = new ImageDto( imageBase64: $image->encode(), width: $image->getWidth(), height: $image->getHeight() ); return new ImageHeadDto(image: $image); } private function processingString(ImageContract $image, Symbols $symbols, ImageHeadConfig $config): Image { $textLeftPadding = $config->getTextPaddingLeft(); $textTopPadding = $config->getTextPaddingTop(); $countSymbols = count($symbols->getSuccess()); $widthPrefix = $image->getWidth() - $textLeftPadding; $imageHeight = $image->getHeight() - $textTopPadding; foreach ($symbols->getSuccess() as $number => $symbol) { $marginLeft = $textLeftPadding + $number * $widthPrefix / $countSymbols; $image->addText( text: $symbol, x: intval($marginLeft), y: $textTopPadding, size: $this->randomFontSize($imageHeight), angle: $config->randomAngle(), hexColor: $config->randomFontColor(), fontName: $config->randomFont() ); } return $image; } private function randomFontSize(int $imageHeight): int { return mt_rand($imageHeight - 10, $imageHeight); } }