renderSvg($matrix, $style); echo "Generated SVG:\n"; echo " Size: " . strlen($svg) . " bytes\n"; // Extract dimensions preg_match('/width="([0-9.]+)"\s+height="([0-9.]+)"/', $svg, $dimMatches); if (!empty($dimMatches)) { echo " Dimensions: {$dimMatches[1]}x{$dimMatches[2]}px\n"; } // Extract all rectangles preg_match_all('/x="([0-9.]+)"\s+y="([0-9.]+)"\s+width="([0-9.]+)"\s+height="([0-9.]+)"\s+fill="([^"]+)"/', $svg, $rectMatches); if (!empty($rectMatches[1])) { $rectCount = count($rectMatches[1]); echo " Rectangles: {$rectCount}\n"; // Check first rectangle $firstX = (float)$rectMatches[1][0]; $firstY = (float)$rectMatches[2][0]; $firstW = (float)$rectMatches[3][0]; $firstH = (float)$rectMatches[4][0]; $firstFill = $rectMatches[5][0]; echo " First rectangle: x={$firstX}, y={$firstY}, w={$firstW}, h={$firstH}, fill={$firstFill}\n"; // Expected first position (quiet zone offset) $expectedOffset = 4 * 20; // 4 modules * 20px echo " Expected offset: {$expectedOffset}px\n"; if (abs($firstX - $expectedOffset) < 1 && abs($firstY - $expectedOffset) < 1) { echo " ✅ Position correct\n"; } else { echo " ❌ Position incorrect!\n"; } if (abs($firstW - 20) < 1 && abs($firstH - 20) < 1) { echo " ✅ Size correct (20px)\n"; } else { echo " ❌ Size incorrect!\n"; } // Count unique positions $positions = []; for ($i = 0; $i < $rectCount; $i++) { $x = (float)$rectMatches[1][$i]; $y = (float)$rectMatches[2][$i]; $positions[] = "{$x},{$y}"; } $uniquePositions = count(array_unique($positions)); echo " Unique positions: {$uniquePositions}\n"; if ($uniquePositions === $rectCount) { echo " ✅ No overlapping rectangles\n"; } else { echo " ❌ Overlapping rectangles detected!\n"; } } // Check colors $blackCount = substr_count($svg, 'fill="black"') + substr_count($svg, 'fill="#000000"') + substr_count($svg, 'fill="#000"'); $whiteCount = substr_count($svg, 'fill="white"') + substr_count($svg, 'fill="#FFFFFF"') + substr_count($svg, 'fill="#ffffff"'); echo "\nColors:\n"; echo " Black fills: {$blackCount}\n"; echo " White fills: {$whiteCount}\n"; // Verify matrix -> SVG mapping echo "\n=== Matrix to SVG Verification ===\n"; $matrixSize = $matrix->getSize(); $darkInMatrix = 0; for ($row = 0; $row < $matrixSize; $row++) { for ($col = 0; $col < $matrixSize; $col++) { if ($matrix->getModuleAt($row, $col)->isDark()) { $darkInMatrix++; } } } echo "Dark modules in matrix: {$darkInMatrix}\n"; echo "Black rectangles in SVG: {$blackCount}\n"; if ($darkInMatrix === $blackCount) { echo "✅ Count matches!\n"; } else { echo "❌ Count mismatch!\n"; echo "This indicates a rendering problem.\n"; } // Save for comparison $outputPath = __DIR__ . '/test-qrcodes/comparison.svg'; file_put_contents($outputPath, $svg); echo "\n✅ Saved comparison SVG: {$outputPath}\n"; // Generate a simple test to verify SVG rendering echo "\n=== SVG Rendering Test ===\n"; echo "Open the SVG in a browser and check:\n"; echo "1. All modules are square\n"; echo "2. No gaps between modules\n"; echo "3. Quiet zone is white\n"; echo "4. QR code is clearly visible\n"; echo "5. Try scanning with phone camera\n";