config['types'] ?? []; if (empty($types)) { $error = __('No captcha type settings!'); report($error); return $this->errService($error); } try { $type = Arr::random($types); /** @var Type $captcha */ $typeCaptcha = new $type['class']( $type['params'] ?? [] ); $symbols = $typeCaptcha->getSymbols(); $imageHeadConfig = $this->makeImageHeadConfig($this->config['image_head'] ?? []); $imageHead = $this->imageHead->processing($symbols, $imageHeadConfig); unset($imageHeadConfig); $imageBodyConfig = $this->makeImageBodyConfig($this->config['image_body'] ?? []); $imageBody = $this->imageBody->processing($symbols, $imageBodyConfig); unset($imageBodyConfig); dd($imageHead, $imageBody); } catch (\Throwable $e) { report($e); return $this->errService('Captcha service error!'); } return new Captcha( imageBase64: $imageHead->getImage()->getImageBase64(), imageTextBase64: $imageBody->getImage()->getImageBase64(), key: 'dddd' ); } private function makeImageHeadConfig(array $params): ImageHeadConfig { return new ImageHeadConfig( backgrounds: $params['backgrounds'] ?? [], fonts: $params['fonts'] ?? [], fontColors: $params['font_colors'] ?? [], width: $params['width'] ?? 150, height: $params['height'] ?? 40, textPaddingTop: $params['text_padding_top'] ?? 5, textPaddingLeft: $params['text_padding_left'] ?? 10, angle: $params['angle'] ?? 20, numberLines: $params['number_lines'] ?? 3, lineColors: $params['line_colors'] ?? [] ); } private function makeImageBodyConfig(array $params): ImageBodyConfig { return new ImageBodyConfig( backgrounds: $params['backgrounds'] ?? [], fonts: $params['fonts'] ?? [], fontColors: $params['font_colors'] ?? [], width: $params['width'] ?? 300, height: $params['height'] ?? 240, angle: $params['angle'] ?? 20, fontSize: $params['font_size'] ?? [20, 50], numberLines: $params['number_lines'] ?? 3, lineColors: $params['line_colors'] ?? [] ); } }