getSize()}x{$matrix->getSize()}\n\n"; // Analyze the matrix structure echo "=== Matrix Analysis ===\n"; // Check format information $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 "Format Information Horizontal: {$formatH}\n"; echo "Format Information Vertical: {$formatV}\n"; echo "Match: " . ($formatH === $formatV ? "✅" : "❌") . "\n\n"; // Decode format info $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 "Decoded Format Information:\n"; echo " EC Level: {$ecLevel}\n"; echo " Mask Pattern: {$maskPattern}\n\n"; // Check finder patterns echo "=== Finder Pattern Check ===\n"; $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']} finder pattern correct\n"; } else { echo "❌ {$finder['name']} finder pattern has {$errors} errors\n"; } } echo "\n"; // Check timing patterns echo "=== Timing Pattern Check ===\n"; $timingOk = true; // Horizontal timing (row 6, cols 8-12) for ($col = 8; $col <= 12; $col++) { $expectedDark = (($col - 8) % 2) === 0; $isDark = $matrix->getModuleAt(6, $col)->isDark(); if ($isDark !== $expectedDark) { $timingOk = false; break; } } // Vertical timing (col 6, rows 8-12) for ($row = 8; $row <= 12; $row++) { $expectedDark = (($row - 8) % 2) === 0; $isDark = $matrix->getModuleAt($row, 6)->isDark(); if ($isDark !== $expectedDark) { $timingOk = false; break; } } if ($timingOk) { echo "✅ Timing patterns correct\n"; } else { echo "❌ Timing patterns incorrect\n"; } echo "\n"; // Generate a new SVG for comparison $renderer = new QrCodeRenderer(); $svg = $renderer->renderSvg($matrix); // Save for comparison $outputPath = __DIR__ . '/test-output.svg'; file_put_contents($outputPath, $svg); echo "✅ Generated comparison SVG: {$outputPath}\n"; echo " Size: " . strlen($svg) . " bytes\n"; // Check if there are any obvious issues echo "\n=== Potential Issues ===\n"; // Check quiet zone $quietZoneOk = true; for ($i = 0; $i < 4; $i++) { // Check top quiet zone if ($matrix->getModuleAt($i, 10)->isDark()) { $quietZoneOk = false; break; } // Check left quiet zone if ($matrix->getModuleAt(10, $i)->isDark()) { $quietZoneOk = false; break; } } if ($quietZoneOk) { echo "✅ Quiet zone appears correct (checked sample)\n"; } else { echo "❌ Quiet zone might have issues\n"; } echo "\n"; echo "=== Next Steps ===\n"; echo "1. Compare the SVG structure with a working reference\n"; echo "2. Check if format information is correctly placed\n"; echo "3. Verify mask pattern application\n"; echo "4. Test with a simpler QR code first\n"; } else { echo "✅ SVG file found\n"; $svgContent = file_get_contents($svgPath); echo "Size: " . strlen($svgContent) . " bytes\n"; // Parse SVG to extract QR code structure // Count rectangles $rectCount = substr_count($svgContent, ' 1) { $moduleSize = $uniqueX[1] - $uniqueX[0]; echo "Module size: {$moduleSize}px\n"; // Calculate quiet zone $firstX = min($uniqueX); $quietZone = $firstX / $moduleSize; echo "Quiet zone: {$quietZone} modules\n"; // Calculate matrix size $matrixSize = (max($uniqueX) - min($uniqueX)) / $moduleSize + 1; echo "Matrix size: {$matrixSize}x{$matrixSize}\n"; } } }