1.1 images added

This commit is contained in:
Flatlogic Bot 2025-10-13 10:51:38 +00:00
parent 0d8e110419
commit 3f6295d575
16 changed files with 89 additions and 6 deletions

58
api/pexels.php Normal file
View File

@ -0,0 +1,58 @@
<?php
header('Content-Type: application/json');
require_once __DIR__.'/../includes/pexels.php';
if (!isset($_GET['action'])) {
echo json_encode(['error' => 'Action not specified']);
exit;
}
$action = $_GET['action'];
if ($action === 'image') {
$q = isset($_GET['query']) ? $_GET['query'] : 'nature';
$orientation = isset($_GET['orientation']) ? $_GET['orientation'] : 'portrait';
$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'])) { echo json_encode(['error'=>'Failed to fetch image']); exit; }
$photo = $data['photos'][0];
$src = $photo['src']['large2x'] ?? ($photo['src']['large'] ?? $photo['src']['original']);
$target = __DIR__ . '/../assets/images/pexels/' . $photo['id'] . '.jpg';
download_to($src, $target);
// Return minimal info and local relative path
echo json_encode([
'id' => $photo['id'],
'local' => 'assets/images/pexels/' . $photo['id'] . '.jpg',
'photographer' => $photo['photographer'] ?? null,
'photographer_url' => $photo['photographer_url'] ?? null,
]);
} elseif ($action === 'multiple') {
$qs = isset($_GET['queries']) ? explode(',', $_GET['queries']) : ['home','apple','pizza','mountains','cat'];
$out = [];
foreach ($qs as $q) {
$u = 'https://api.pexels.com/v1/search?query=' . urlencode(trim($q)) . '&orientation=square&per_page=1&page=1';
$d = pexels_get($u);
if ($d && !empty($d['photos'])) {
$p = $d['photos'][0];
$src = $p['src']['original'] ?? null;
$dest = __DIR__.'/../assets/images/pexels/'.$p['id'].'.jpg';
if ($src) download_to($src, $dest);
$out[] = [
'src' => 'assets/images/pexels/'.$p['id'].'.jpg',
'photographer' => $p['photographer'] ?? 'Unknown',
'photographer_url' => $p['photographer_url'] ?? '',
];
} else {
// Fallback: Picsum
$out[] = [
'src' => 'https://picsum.photos/600',
'photographer' => 'Random Picsum',
'photographer_url' => 'https://picsum.photos/'
];
}
}
echo json_encode($out);
} else {
echo json_encode(['error' => 'Invalid action']);
exit;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 361 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 979 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 817 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 114 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 476 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 113 KiB

25
includes/pexels.php Normal file
View File

@ -0,0 +1,25 @@
<?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;
}

View File

@ -58,7 +58,7 @@
<div class="product-grid"> <div class="product-grid">
<!-- Product 1: Pumpkins --> <!-- Product 1: Pumpkins -->
<div class="product-card"> <div class="product-card">
<img src="https://images.pexels.com/photos/1399284/pexels-photo-1399284.jpeg?auto=compress&cs=tinysrgb&w=600" alt="A collection of pumpkins"> <img src="assets/pasted-20251013-104427-e367c0e6.jpg?v=<?php echo time(); ?>" alt="Pumpkin">
<div class="product-info"> <div class="product-info">
<h3>Festive Pumpkins</h3> <h3>Festive Pumpkins</h3>
<p>Perfect for carving, decorating, or making delicious pies.</p> <p>Perfect for carving, decorating, or making delicious pies.</p>
@ -68,7 +68,7 @@
<!-- Product 2: More Pumpkins --> <!-- Product 2: More Pumpkins -->
<div class="product-card"> <div class="product-card">
<img src="https://images.pexels.com/photos/2646337/pexels-photo-2646337.jpeg?auto=compress&cs=tinysrgb&w=600" alt="A collection of pumpkins"> <img src="assets/pasted-20251013-104527-870b56ba.jpg?v=<?php echo time(); ?>" alt="Cinderella pumpkin">
<div class="product-info"> <div class="product-info">
<h3>Heirloom Pumpkins</h3> <h3>Heirloom Pumpkins</h3>
<p>A variety of shapes and sizes for the perfect autumn display.</p> <p>A variety of shapes and sizes for the perfect autumn display.</p>
@ -78,7 +78,7 @@
<!-- Product 3: Small Pumpkins --> <!-- Product 3: Small Pumpkins -->
<div class="product-card"> <div class="product-card">
<img src="https://images.pexels.com/photos/5647592/pexels-photo-5647592.jpeg?auto=compress&cs=tinysrgb&w=600" alt="A variety of decorative gourds"> <img src="assets/pasted-20251013-104632-6da13ed6.jpg?v=<?php echo time(); ?>" alt="Jarrahdale pumpkin">
<div class="product-info"> <div class="product-info">
<h3>Mini Pumpkins</h3> <h3>Mini Pumpkins</h3>
<p>Ideal for tabletop decorations and adding a festive touch.</p> <p>Ideal for tabletop decorations and adding a festive touch.</p>
@ -96,7 +96,7 @@
<div class="product-grid"> <div class="product-grid">
<!-- Product 1: Persimmons --> <!-- Product 1: Persimmons -->
<div class="product-card"> <div class="product-card">
<img src="https://images.pexels.com/photos/5641983/pexels-photo-5641983.jpeg?auto=compress&cs=tinysrgb&w=600" alt="Ripe persimmons on a branch"> <img src="assets/pasted-20251013-104838-d263cbfd.jpg?v=<?php echo time(); ?>" alt="Fuyu persimmon">
<div class="product-info"> <div class="product-info">
<h3>Sweet Persimmons</h3> <h3>Sweet Persimmons</h3>
<p>Juicy, sweet, and ready to eat. A true taste of autumn.</p> <p>Juicy, sweet, and ready to eat. A true taste of autumn.</p>
@ -106,7 +106,7 @@
<!-- Product 2: More Persimmons --> <!-- Product 2: More Persimmons -->
<div class="product-card"> <div class="product-card">
<img src="https://images.pexels.com/photos/6157053/pexels-photo-6157053.jpeg?auto=compress&cs=tinysrgb&w=600" alt="Ripe persimmons on a branch"> <img src="assets/pasted-20251013-105020-30d37036.png?v=<?php echo time(); ?>" alt="Hachiya persimmon">
<div class="product-info"> <div class="product-info">
<h3>Fuyu Persimmons</h3> <h3>Fuyu Persimmons</h3>
<p>Crisp, sweet, and non-astringent. Perfect for salads.</p> <p>Crisp, sweet, and non-astringent. Perfect for salads.</p>
@ -116,7 +116,7 @@
<!-- Product 3: Dried Persimmons --> <!-- Product 3: Dried Persimmons -->
<div class="product-card"> <div class="product-card">
<img src="https://images.pexels.com/photos/1092728/pexels-photo-1092728.jpeg?auto=compress&cs=tinysrgb&w=600" alt="A variety of decorative gourds"> <img src="assets/pasted-20251013-105058-e81307c0.webp?v=<?php echo time(); ?>" alt="Triumph persimmon">
<div class="product-info"> <div class="product-info">
<h3>Dried Persimmons</h3> <h3>Dried Persimmons</h3>
<p>A sweet and chewy snack, naturally preserved.</p> <p>A sweet and chewy snack, naturally preserved.</p>