class BasicCaptchaGenerator extends AbstractBasicCaptchaGenerator
{ private const FALLBACK_WIDTH_IMAGE = 390;
private const FALLBACK_HEIGHT_IMAGE = 65;
private string
$backgroundPath = __DIR__ . '/../../../Resources/app/storefront/dist/assets/captcha/background.png';
private string
$fontPath = __DIR__ . '/../../../Resources/app/storefront/dist/assets/captcha/font.ttf';
public function generate(int
$length = 7
): BasicCaptchaImage
{ $code =
$this->
createCaptchaCode($length);
$filesystem =
new Filesystem();
if ($filesystem->
exists($this->backgroundPath
)) { /** @var \GdImage $img */
$img =
imagecreatefrompng($this->backgroundPath
);
} else { /** @var \GdImage $img */
$img =
imagecreate(self::FALLBACK_WIDTH_IMAGE, self::FALLBACK_HEIGHT_IMAGE
);
imagecolorallocate($img, 255, 255, 255
);
}