paths of the written PNG files */ public static function export(string $htmlPath, string $targetDir): array { $html = (string) file_get_contents($htmlPath); if (preg_match_all('/src="data:image\/png;base64,([^"]+)"/', $html, $matches) === false || ! isset($matches[1][2])) { return []; } $base = pathinfo($htmlPath, PATHINFO_FILENAME); $labels = ['diff', 'expected', 'actual']; $written = []; foreach (array_slice($matches[1], 0, 3) as $index => $base64) { $path = $targetDir.'/'.$base.'-'.($labels[$index] ?? 'image-'.$index).'.png'; if (file_put_contents($path, (string) base64_decode($base64, true)) === false) { continue; } $written[] = $path; } return $written; } }