20 lines
831 B
PHP
20 lines
831 B
PHP
<?php
|
|
require_once __DIR__.'/../includes/pexels.php';
|
|
$q = 'bell';
|
|
$orientation = 'square';
|
|
$url = 'https://api.pexels.com/v1/search?query=' . urlencode($q) . '&orientation=' . urlencode($orientation) . '&per_page=1&page=1';
|
|
$data = pexels_get($url);
|
|
if (!$data || empty($data['photos'])) {
|
|
// Fallback to a generic image if Pexels fails
|
|
$src = 'https://picsum.photos/200';
|
|
$target = __DIR__ . '/../assets/images/bell.png';
|
|
download_to($src, $target);
|
|
echo json_encode(['success' => true, 'local' => 'assets/images/bell.png']);
|
|
exit;
|
|
}
|
|
$photo = $data['photos'][0];
|
|
$src = $photo['src']['tiny'] ?? ($photo['src']['small'] ?? $photo['src']['original']);
|
|
$target = __DIR__ . '/../assets/images/bell.png';
|
|
download_to($src, $target);
|
|
echo json_encode(['success' => true, 'local' => 'assets/images/bell.png']);
|