1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// This val creates a publicly accessible kitten image generator using the Val Town image generation API.
// It supports generating square images with a single dimension parameter or rectangular images with two dimension parameters.
export default async function server(request: Request): Promise<Response> {
const url = new URL(request.url);
const parts = url.pathname.split('/').filter(Boolean);
if (parts.length === 0) {
const welcomeHtml = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Kitten Image Generator</title>
<style>
body {
font-family: Arial, sans-serif;
line-height: 1.6;
color: #333;
max-width: 800px;
margin: 0 auto;
padding: 20px;
background-color: #f4f4f4;
}
h1 {
color: #2c3e50;
text-align: center;
}
p {
margin-bottom: 20px;
}
.example-image {
display: block;
max-width: 100%;
height: auto;
margin: 20px auto;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}
.instructions, .form-container {
background-color: #fff;
border-left: 4px solid #3498db;
padding: 15px;
margin-bottom: 20px;
border-radius: 0 5px 5px 0;
}
code {
background-color: #e7e7e7;
padding: 2px 4px;
border-radius: 4px;
}
form {
display: flex;
flex-direction: column;
gap: 10px;
}
input[type="number"] {
padding: 5px;
border: 1px solid #ccc;
border-radius: 4px;
}
button {
padding: 10px;
background-color: #3498db;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background-color: #2980b9;
}
</style>
</head>
<body>
<h1>Welcome to the Kitten Image Generator!</h1>
<div class="instructions">
<p>Use this service to generate cute kitten images of various sizes:</p>
<p>For square images: <code>/width</code> (e.g., <code>/400</code> for a 400x400 image)</p>
<p>For rectangular images: <code>/width/height</code> (e.g., <code>/400/300</code> for a 400x300 image)</p>
</div>
<div class="form-container">
<h2>Generate a Kitten Image</h2>
<form id="kittenForm">
<label for="width">Width (64-1024):</label>
<input type="number" id="width" name="width" min="64" max="1024" required>
<label for="height">Height (64-1024):</label>
<input type="number" id="height" name="height" min="64" max="1024" required>
<button type="submit">Generate Kitten</button>
</form>
</div>
<p>Here's an example of a generated 400x400 kitten image:</p>
<img src="/400" alt="Example 400x400 kitten" class="example-image">
<p>Start generating your own kitten images by using the form above or modifying the URL!</p>
<script>
document.getElementById('kittenForm').addEventListener('submit', function(e) {
e.preventDefault();
const width = document.getElementById('width').value;
const height = document.getElementById('height').value;