Novis\Image\QrCode::Level
How much of a QR code can be damaged and still be read.
QrCode::Level is declared in the class Novis\Image\QrCode.
You pass a QrCode::Level to QrCode::render as level. A QR code stores extra data to repair the parts a scanner cannot read. Dirt or a logo on top of the code can hide such parts. This is called error correction. The default is Medium.
Lowrepairs about 7 percent of the code.Mediumrepairs about 15 percent.Quartilerepairs about 25 percent, which is a quarter of the code.Highrepairs about 30 percent.
A higher level needs more squares for the same text, so the code gets bigger. When the text is too long for the level, render throws a LogicError.
Examples
More repair more modules
<?nvs// Shows that a higher `QrCode::Level` makes a bigger QR code for the same text.use Novis\Image\QrCode;
class Squares{ // Returns how many squares wide the code is. A code is 21, 25, 29 or more squares wide, // and `render` throws a `LogicError` when `size` is smaller than the code. public static function across(string $text, QrCode::Level $level): uint { uint $size = 21; while (true) { try { QrCode::render($text, { size: $size, margin: 0, level: $level }); return $size; } catch (LogicError $e) { $size = $size + 4; } } }}
string $link = 'https://example.com/orders/1042';
array<QrCode::Level> $levels = [QrCode::Level::Low, QrCode::Level::Medium, QrCode::Level::Quartile, QrCode::Level::High];
// This prints 25, 29, 29 and 33.foreach ($levels as QrCode::Level $level) { echo Squares::across($link, $level), "\n";}25292933