34334-vm/api/pexels.php
Flatlogic Bot d5d05fd44f 03
2025-09-24 06:37:02 +00:00

40 lines
1.3 KiB
PHP

<?php
header('Content-Type: application/json');
require_once __DIR__.'/../includes/pexels.php';
// Fetch a variety of professional-looking document/resume templates
$query = 'resume template document';
$orientation = 'portrait';
$per_page = 12;
$url = 'https://api.pexels.com/v1/search?query=' . urlencode($query) . '&orientation=' . urlencode($orientation) . '&per_page=' . $per_page;
$data = pexels_get($url);
if (!$data || empty($data['photos'])) {
echo json_encode(['error' => '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);
?>