:octocat: QRMatrix: ignore logo w/h 0, throw on invalid dimensions

This commit is contained in:
codemasher
2021-12-08 16:36:17 +01:00
parent ae69a5ae6c
commit 1aee1e90ca
2 changed files with 14 additions and 4 deletions
+13 -3
View File
@@ -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');
+1 -1
View File
@@ -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);
}
/**