diff --git a/api/pexels.php b/api/pexels.php new file mode 100644 index 0000000..1b357d8 --- /dev/null +++ b/api/pexels.php @@ -0,0 +1,58 @@ + '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; +} diff --git a/assets/images/pexels/102104.jpg b/assets/images/pexels/102104.jpg new file mode 100644 index 0000000..7e776ad Binary files /dev/null and b/assets/images/pexels/102104.jpg differ diff --git a/assets/images/pexels/1115804.jpg b/assets/images/pexels/1115804.jpg new file mode 100644 index 0000000..6b65d5c Binary files /dev/null and b/assets/images/pexels/1115804.jpg differ diff --git a/assets/images/pexels/2173872.jpg b/assets/images/pexels/2173872.jpg new file mode 100644 index 0000000..e30610b Binary files /dev/null and b/assets/images/pexels/2173872.jpg differ diff --git a/assets/images/pexels/2762939.jpg b/assets/images/pexels/2762939.jpg new file mode 100644 index 0000000..c26206f Binary files /dev/null and b/assets/images/pexels/2762939.jpg differ diff --git a/assets/images/pexels/5435190.jpg b/assets/images/pexels/5435190.jpg new file mode 100644 index 0000000..e7f9d2c Binary files /dev/null and b/assets/images/pexels/5435190.jpg differ diff --git a/assets/images/pexels/842687.jpg b/assets/images/pexels/842687.jpg new file mode 100644 index 0000000..e160b6b Binary files /dev/null and b/assets/images/pexels/842687.jpg differ diff --git a/assets/pasted-20251013-101706-c321c3dc.png b/assets/pasted-20251013-101706-c321c3dc.png new file mode 100644 index 0000000..c187738 Binary files /dev/null and b/assets/pasted-20251013-101706-c321c3dc.png differ diff --git a/assets/pasted-20251013-104427-e367c0e6.jpg b/assets/pasted-20251013-104427-e367c0e6.jpg new file mode 100644 index 0000000..e24accf Binary files /dev/null and b/assets/pasted-20251013-104427-e367c0e6.jpg differ diff --git a/assets/pasted-20251013-104527-870b56ba.jpg b/assets/pasted-20251013-104527-870b56ba.jpg new file mode 100644 index 0000000..96ca458 Binary files /dev/null and b/assets/pasted-20251013-104527-870b56ba.jpg differ diff --git a/assets/pasted-20251013-104632-6da13ed6.jpg b/assets/pasted-20251013-104632-6da13ed6.jpg new file mode 100644 index 0000000..05854b3 Binary files /dev/null and b/assets/pasted-20251013-104632-6da13ed6.jpg differ diff --git a/assets/pasted-20251013-104838-d263cbfd.jpg b/assets/pasted-20251013-104838-d263cbfd.jpg new file mode 100644 index 0000000..aa3b143 Binary files /dev/null and b/assets/pasted-20251013-104838-d263cbfd.jpg differ diff --git a/assets/pasted-20251013-105020-30d37036.png b/assets/pasted-20251013-105020-30d37036.png new file mode 100644 index 0000000..53e8ec2 Binary files /dev/null and b/assets/pasted-20251013-105020-30d37036.png differ diff --git a/assets/pasted-20251013-105058-e81307c0.webp b/assets/pasted-20251013-105058-e81307c0.webp new file mode 100644 index 0000000..3e932c8 Binary files /dev/null and b/assets/pasted-20251013-105058-e81307c0.webp differ diff --git a/includes/pexels.php b/includes/pexels.php new file mode 100644 index 0000000..0c04a85 --- /dev/null +++ b/includes/pexels.php @@ -0,0 +1,25 @@ + 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; +} diff --git a/index.php b/index.php index 492cb17..6135f3b 100644 --- a/index.php +++ b/index.php @@ -58,7 +58,7 @@
- A collection of pumpkins + Pumpkin

Festive Pumpkins

Perfect for carving, decorating, or making delicious pies.

@@ -68,7 +68,7 @@
- A collection of pumpkins + Cinderella pumpkin

Heirloom Pumpkins

A variety of shapes and sizes for the perfect autumn display.

@@ -78,7 +78,7 @@
- A variety of decorative gourds + Jarrahdale pumpkin

Mini Pumpkins

Ideal for tabletop decorations and adding a festive touch.

@@ -96,7 +96,7 @@
- Ripe persimmons on a branch + Fuyu persimmon

Sweet Persimmons

Juicy, sweet, and ready to eat. A true taste of autumn.

@@ -106,7 +106,7 @@
- Ripe persimmons on a branch + Hachiya persimmon

Fuyu Persimmons

Crisp, sweet, and non-astringent. Perfect for salads.

@@ -116,7 +116,7 @@
- A variety of decorative gourds + Triumph persimmon

Dried Persimmons

A sweet and chewy snack, naturally preserved.