jordonpeter01 commited on
Commit
5bb1766
·
verified ·
1 Parent(s): c7e18cf

Add 2 files

Browse files
Files changed (2) hide show
  1. index.html +1 -19
  2. main.js +80 -0
index.html CHANGED
@@ -1,19 +1 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
1
+ <html><head><link href="https://cdn.jsdelivr.net/npm/daisyui@3.1.6/dist/full.css" rel="stylesheet" type="text/css" /><script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script><script src="https://cdn.tailwindcss.com?plugins=forms,typography,aspect-ratio"></script><script defer src="https://cdnjs.cloudflare.com/ajax/libs/three.js/0.156.1/three.min.js"></script><script type="module" src="main.js"></script><title>Image Generator</title></head><body><nav><ul class="container"><li><a href="/">Image Generator</a></li><li><a href="/about">About</a></li></ul></nav><main class="container"><h1>Image Generator</h1><p>Generate your own images!</p><form><label for="name">Name:</label><input type="text" id="name" required><label for="age">Age:</label><input type="number" id="age" required><label for="email">Email:</label><input type="email" id="email" required></form><button id="generate">Generate</button><img id="output" src="#"></main></body></html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
main.js ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Generate button click event listener
2
+ document.getElementById("generate").addEventListener("click", generate);
3
+
4
+ // Generate button disabled until all fields are filled
5
+ document.querySelectorAll("input").forEach((input) => {
6
+ input.addEventListener("input", () => {
7
+ document.getElementById("generate").disabled = false;
8
+ });
9
+ });
10
+
11
+ // Generate image
12
+ async function generate() {
13
+ const name = document.getElementById("name").value;
14
+ const age = document.getElementById("age").value;
15
+ const email = document.getElementById("email").value;
16
+ const canvas = document.getElementById("output");
17
+
18
+ if (!name || !age || !email) {
19
+ return;
20
+ }
21
+
22
+ const renderer = new THREE.WebGLRenderer({
23
+ canvas,
24
+ });
25
+
26
+ const camera = new THREE.PerspectiveCamera(
27
+ 75,
28
+ window.innerWidth / window.innerHeight,
29
+ 0.1,
30
+ 1000
31
+ );
32
+
33
+ const scene = new THREE.Scene();
34
+
35
+ const geometry = new THREE.TextBufferGeometry(name, {
36
+ font: font,
37
+ size: 0.3,
38
+ height: 0.1,
39
+ curveSegments: 10,
40
+ });
41
+
42
+ const material = new THREE.MeshBasicMaterial({});
43
+
44
+ const text = new THREE.Mesh(geometry, material);
45
+ text.position.z = 2;
46
+ text.position.x = -1.5;
47
+ text.position.y = -1.5;
48
+
49
+ const geometry2 = new THREE.TextBufferGeometry(age, {
50
+ font: font,
51
+ size: 0.3,
52
+ height: 0.1,
53
+ curveSegments: 10,
54
+ });
55
+
56
+ const material2 = new THREE.MeshBasicMaterial({});
57
+
58
+ const text2 = new THREE.Mesh(geometry2, material2);
59
+ text2.position.z = 2;
60
+ text2.position.x = 1.5;
61
+ text2.position.y = -1.5;
62
+
63
+ scene.add(text);
64
+ scene.add(text2);
65
+
66
+ renderer.render(scene, camera);
67
+
68
+ const imgUri = await renderer.domElement.toDataURL("image/jpeg");
69
+ const link = document.createElement("a");
70
+ link.href = imgUri;
71
+ link.setAttribute("download", "image.jpg");
72
+ document.body.appendChild(link);
73
+ link.click();
74
+ }
75
+
76
+ // Get font
77
+ const loader = new THREE.FontLoader();
78
+ loader.load("https://unpkg.com/three@0.156.1/examples/fonts/helvetiker_regular.typeface.json", (font) => {
79
+ generate(font);
80
+ });