mirror of
https://github.com/chillerlan/php-qrcode.git
synced 2026-09-02 21:47:22 +00:00
:octocat: QRMatrix: ignore logo w/h 0, throw on invalid dimensions
This commit is contained in:
+13
-3
@@ -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');
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user