diff --git a/src/Data/QRMatrix.php b/src/Data/QRMatrix.php index 9790f44e1..a40b01eab 100755 --- a/src/Data/QRMatrix.php +++ b/src/Data/QRMatrix.php @@ -477,6 +477,19 @@ final class QRMatrix{ throw new QRCodeDataException('ECC level "H" required to add logo space'); } + // if width and height happen to be exactly 0 (default value), just return - nothing to do + if($width === 0 || $height === 0){ + return $this; + } + + // $this->moduleCount includes the quiet zone (if created), we need the QR size here + $length = $this->version->getDimension(); + + // throw if the size is negative or exceeds the qrcode size + if($width < 0 || $height < 0 || $width > $length || $height > $length){ + throw new QRCodeDataException('invalid logo dimensions'); + } + // we need uneven sizes to center the logo space, adjust if needed if($startX === null && ($width % 2) === 0){ $width++; @@ -486,9 +499,6 @@ final class QRMatrix{ $height++; } - // $this->moduleCount includes the quiet zone (if created), we need the QR size here - $length = $this->version->getDimension(); - // throw if the logo space exceeds the maximum error correction capacity if($width * $height > floor($length * $length * 0.2)){ throw new QRCodeDataException('logo space exceeds the maximum error correction capacity'); diff --git a/tests/Data/QRMatrixTest.php b/tests/Data/QRMatrixTest.php index b152eb3b2..d86e21805 100755 --- a/tests/Data/QRMatrixTest.php +++ b/tests/Data/QRMatrixTest.php @@ -344,7 +344,7 @@ final class QRMatrixTest extends TestCase{ $o->version = 5; $o->eccLevel = EccLevel::H; - (new QRCode($o))->addByteSegment('testdata')->getMatrix()->setLogoSpace(50, 50); + (new QRCode($o))->addByteSegment('testdata')->getMatrix()->setLogoSpace(37, 37); } /**