'Failed to fetch images from Pexels.']); exit; } $output = []; foreach ($data['photos'] as $photo) { // Use a smaller, optimized image for the grid view $src = $photo['src']['large'] ?? $photo['src']['original']; $filename = $photo['id'] . '.jpg'; $local_path = __DIR__ . '/../assets/images/pexels/' . $filename; // Download the image if it doesn't already exist to avoid repeated downloads if (!file_exists($local_path)) { download_to($src, $local_path); } $output[] = [ 'id' => $photo['id'], 'local_url' => 'assets/images/pexels/' . $filename, 'photographer' => $photo['photographer'] ?? 'Unknown', 'photographer_url' => $photo['photographer_url'] ?? '#', 'alt' => $photo['alt'] ?? 'Resume template preview' ]; } echo json_encode($output); ?>