getSize(); echo "Matrix size: {$size}x{$size}\n\n"; // Detailed validation echo "=== Detailed Validation ===\n\n"; // 1. Format Information echo "1. Format Information:\n"; $formatCols = [0, 1, 2, 3, 4, 5, 7, 8, 20, 19, 18, 17, 16, 15, 14]; $formatH = ''; foreach ($formatCols as $col) { $formatH .= $matrix->getModuleAt(8, $col)->isDark() ? '1' : '0'; } $formatRows = [20, 19, 18, 17, 16, 15, 14, 8, 7, 5, 4, 3, 2, 1, 0]; $formatV = ''; foreach ($formatRows as $row) { $formatV .= $matrix->getModuleAt($row, 8)->isDark() ? '1' : '0'; } echo " Horizontal: {$formatH}\n"; echo " Vertical: {$formatV}\n"; if ($formatH === $formatV) { echo " ✅ Match\n"; // Decode $xorMask = "101010000010010"; $unmasked = ''; for ($i = 0; $i < 15; $i++) { $unmasked .= (int)$formatH[$i] ^ (int)$xorMask[$i]; } $ecBits = substr($unmasked, 0, 2); $maskBits = substr($unmasked, 2, 5); $ecLevel = match($ecBits) { '01' => 'L', '00' => 'M', '11' => 'Q', '10' => 'H', default => 'UNKNOWN' }; $maskPattern = bindec($maskBits); echo " EC Level: {$ecLevel}\n"; echo " Mask Pattern: {$maskPattern}\n"; } else { echo " ❌ MISMATCH - This will cause scanning to fail!\n"; } echo "\n"; // 2. Finder Patterns echo "2. Finder Patterns:\n"; $finderOk = true; $finderPatterns = [ ['name' => 'Top-Left', 'row' => 0, 'col' => 0], ['name' => 'Top-Right', 'row' => 0, 'col' => 14], ['name' => 'Bottom-Left', 'row' => 14, 'col' => 0], ]; $expectedFinder = [ [1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 1], [1, 0, 1, 1, 1, 0, 1], [1, 0, 1, 1, 1, 0, 1], [1, 0, 1, 1, 1, 0, 1], [1, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1], ]; foreach ($finderPatterns as $finder) { $errors = 0; for ($r = 0; $r < 7; $r++) { for ($c = 0; $c < 7; $c++) { $row = $finder['row'] + $r; $col = $finder['col'] + $c; $isDark = $matrix->getModuleAt($row, $col)->isDark(); $expectedDark = $expectedFinder[$r][$c] === 1; if ($isDark !== $expectedDark) { $errors++; } } } if ($errors === 0) { echo " ✅ {$finder['name']}\n"; } else { echo " ❌ {$finder['name']} ({$errors} errors)\n"; $finderOk = false; } } if (!$finderOk) { echo " ⚠️ Finder pattern errors will prevent scanning!\n"; } echo "\n"; // 3. Timing Patterns echo "3. Timing Patterns:\n"; $timingOk = true; // Horizontal (row 6, cols 8-12) $timingH = ''; for ($col = 8; $col <= 12; $col++) { $isDark = $matrix->getModuleAt(6, $col)->isDark(); $expectedDark = (($col - 8) % 2) === 0; $timingH .= $isDark ? '1' : '0'; if ($isDark !== $expectedDark) { $timingOk = false; } } // Vertical (col 6, rows 8-12) $timingV = ''; for ($row = 8; $row <= 12; $row++) { $isDark = $matrix->getModuleAt($row, 6)->isDark(); $expectedDark = (($row - 8) % 2) === 0; $timingV .= $isDark ? '1' : '0'; if ($isDark !== $expectedDark) { $timingOk = false; } } echo " Horizontal: {$timingH}\n"; echo " Vertical: {$timingV}\n"; if ($timingOk) { echo " ✅ Correct\n"; } else { echo " ❌ Incorrect\n"; } echo "\n"; // 4. Dark Module echo "4. Dark Module:\n"; $darkModuleRow = 4 * 1 + 9; // Version 1 $darkModuleCol = 8; $isDark = $matrix->getModuleAt($darkModuleRow, $darkModuleCol)->isDark(); if ($isDark) { echo " ✅ Present at ({$darkModuleRow}, {$darkModuleCol})\n"; } else { echo " ❌ Missing at ({$darkModuleRow}, {$darkModuleCol})\n"; } echo "\n"; // 5. Generate optimized SVG echo "=== Generating Optimized SVG ===\n"; $renderer = new QrCodeRenderer(); $svg = $renderer->renderSvg($matrix); // Save $outputDir = __DIR__ . '/test-qrcodes'; if (!is_dir($outputDir)) { mkdir($outputDir, 0755, true); } $outputPath = $outputDir . '/scannable-test.svg'; file_put_contents($outputPath, $svg); echo "✅ Saved: {$outputPath}\n"; echo " Size: " . strlen($svg) . " bytes\n"; // Check SVG structure $rectCount = substr_count($svg, '