22 lines
710 B
PHP
22 lines
710 B
PHP
<?php
|
|
require_once __DIR__ . '/includes/pexels.php';
|
|
|
|
function fetch_image($query, $filename) {
|
|
$url = 'https://api.pexels.com/v1/search?query=' . urlencode($query) . '&per_page=1&page=1';
|
|
$data = pexels_get($url);
|
|
if ($data && !empty($data['photos'])) {
|
|
$photo = $data['photos'][0];
|
|
$src = $photo['src']['large2x'] ?? $photo['src']['large'];
|
|
$dest = __DIR__ . '/assets/images/' . $filename;
|
|
download_to($src, $dest);
|
|
return 'assets/images/' . $filename;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
// Fetch background
|
|
fetch_image('dark music studio radio', 'background.jpg');
|
|
// Fetch featured photo
|
|
fetch_image('radio dj turntable', 'featured.jpg');
|
|
echo "Images fetched.";
|