Auto commit: 2026-02-15T02:05:59.651Z
This commit is contained in:
parent
cea3a456b9
commit
0006691f0c
BIN
assets/images/programs/deep_night.jpg
Normal file
BIN
assets/images/programs/deep_night.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 165 KiB |
BIN
assets/images/programs/lili_guest.jpg
Normal file
BIN
assets/images/programs/lili_guest.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 109 KiB |
BIN
assets/images/programs/techno_sunrise.jpg
Normal file
BIN
assets/images/programs/techno_sunrise.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 145 KiB |
BIN
assets/images/programs/vocal_house.jpg
Normal file
BIN
assets/images/programs/vocal_house.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 143 KiB |
27
fetch_program_images.php
Normal file
27
fetch_program_images.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/includes/pexels.php';
|
||||
|
||||
$programs = [
|
||||
'techno_sunrise' => 'techno club sunrise',
|
||||
'vocal_house' => 'vocal house music dj',
|
||||
'lili_guest' => 'professional dj booth',
|
||||
'deep_night' => 'night city lights chill'
|
||||
];
|
||||
|
||||
foreach ($programs as $id => $query) {
|
||||
echo "Fetching image for $id ($query)...\n";
|
||||
$url = 'https://api.pexels.com/v1/search?query=' . urlencode($query) . '&orientation=landscape&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/programs/' . $id . '.jpg';
|
||||
if (download_to($src, $dest)) {
|
||||
echo "Saved to $dest\n";
|
||||
} else {
|
||||
echo "Failed to download $src\n";
|
||||
}
|
||||
} else {
|
||||
echo "No photos found for $query\n";
|
||||
}
|
||||
}
|
||||
27
includes/pexels.php
Normal file
27
includes/pexels.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
function pexels_key() {
|
||||
$k = getenv('PEXELS_KEY');
|
||||
return $k && strlen($k) > 0 ? $k : 'Vc99rnmOhHhJAbgGQoKLZtsaIVfkeownoQNbTj78VemUjKh08ZYRbf18';
|
||||
}
|
||||
|
||||
function pexels_get($url) {
|
||||
$ch = curl_init();
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_URL => $url,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_HTTPHEADER => [ 'Authorization: '. pexels_key() ],
|
||||
CURLOPT_TIMEOUT => 15,
|
||||
]);
|
||||
$resp = curl_exec($ch);
|
||||
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
if ($code >= 200 && $code < 300 && $resp) return json_decode($resp, true);
|
||||
return null;
|
||||
}
|
||||
|
||||
function download_to($srcUrl, $destPath) {
|
||||
$data = @file_get_contents($srcUrl);
|
||||
if ($data === false) return false;
|
||||
if (!is_dir(dirname($destPath))) mkdir(dirname($destPath), 0775, true);
|
||||
return file_put_contents($destPath, $data) !== false;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user