40 lines
1.3 KiB
PHP
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);
|
|
?>
|