From 0095706c3bf2389f15f6c097bab4a00a48fc5ff7 Mon Sep 17 00:00:00 2001 From: Jeroen van den Enden Date: Sat, 1 Dec 2018 12:34:40 +0000 Subject: [PATCH] Fix error correction level handling --- README.md | 2 +- src/Factory/QrCodeFactory.php | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f877b72..af6fc02 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ $qrCode->setSize(300); $qrCode->setWriterByName('png'); $qrCode->setMargin(10); $qrCode->setEncoding('UTF-8'); -$qrCode->setErrorCorrectionLevel(ErrorCorrectionLevel::HIGH); +$qrCode->setErrorCorrectionLevel(new ErrorCorrectionLevel(ErrorCorrectionLevel::HIGH)); $qrCode->setForegroundColor(['r' => 0, 'g' => 0, 'b' => 0, 'a' => 0]); $qrCode->setBackgroundColor(['r' => 255, 'g' => 255, 'b' => 255, 'a' => 0]); $qrCode->setLabel('Scan the code', 16, __DIR__.'/../assets/fonts/noto_sans.otf', LabelAlignment::CENTER); diff --git a/src/Factory/QrCodeFactory.php b/src/Factory/QrCodeFactory.php index b7079f4..57342bd 100644 --- a/src/Factory/QrCodeFactory.php +++ b/src/Factory/QrCodeFactory.php @@ -11,6 +11,7 @@ namespace Endroid\QrCode\Factory; +use Endroid\QrCode\ErrorCorrectionLevel; use Endroid\QrCode\QrCode; use Endroid\QrCode\QrCodeInterface; use Endroid\QrCode\WriterRegistryInterface; @@ -66,6 +67,9 @@ public function create(string $text = '', array $options = []): QrCodeInterface $options['writer_by_name'] = $options[$option]; $option = 'writer_by_name'; } + if ('error_correction_level' === $option) { + $options[$option] = new ErrorCorrectionLevel($options[$option]); + } $accessor->setValue($qrCode, $option, $options[$option]); } }