Juno360219 commited on
Commit
43634b6
·
verified ·
1 Parent(s): b1d3668

Upload 2 files

Browse files
Files changed (2) hide show
  1. README.md +7 -6
  2. index.html +48 -19
README.md CHANGED
@@ -1,11 +1,12 @@
1
  ---
2
  title: Tiny Sprite Maker
3
- emoji: 🚀
4
- colorFrom: red
5
- colorTo: red
6
  sdk: static
 
7
  pinned: false
8
- short_description: Tiny Sprite Maker
9
  ---
10
-
11
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
  title: Tiny Sprite Maker
3
+ emoji: 👾
4
+ colorFrom: indigo
5
+ colorTo: gray
6
  sdk: static
7
+ app_file: index.html
8
  pinned: false
9
+ license: mit
10
  ---
11
+ # Tiny Sprite Maker
12
+ GBA-compact sprites from any picture, entirely in the browser: centre-crop, shrink to 32x32 / 32x48 / 48x64 / 64x64, quantize to an 8-32 colour palette, download the true-size PNG. Built for Jessie's Dungeon Dice game.
index.html CHANGED
@@ -1,19 +1,48 @@
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
+ <!DOCTYPE html>
2
+ <html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">
3
+ <title>Tiny Sprite Maker</title>
4
+ <style>body{font-family:system-ui;background:#16161e;color:#eee;margin:0;padding:16px}h1{font-size:22px}
5
+ .card{background:#22222e;border-radius:12px;padding:14px;margin:12px 0}canvas{image-rendering:pixelated;background:#101018;border:1px solid #444}
6
+ button,input,select{font-size:16px;margin:4px;padding:8px}img{image-rendering:pixelated}</style></head>
7
+ <body><h1>👾 Tiny Sprite Maker</h1>
8
+ <p>GBA-compact sprites from any picture: shrink it right down, lock it to a tiny palette, get a true-size PNG (often under 2 KB). Everything runs in your browser — no server, no GPU.</p>
9
+ <div class="card">
10
+ <input type="file" id="file" accept="image/*"><br>
11
+ <label>Sprite size: <select id="size"><option value="32x32">32×32</option><option value="32x48">32×48</option><option value="48x64" selected>48×64</option><option value="64x64">64×64</option></select></label>
12
+ <label>Palette colours: <select id="cols"><option>8</option><option selected>16</option><option>32</option></select></label>
13
+ <button id="go">Make tiny sprite</button>
14
+ </div>
15
+ <div class="card"><h3>True-size sprite</h3><canvas id="out" width="48" height="64"></canvas><br><a id="dl" download="tiny-sprite.png">Download sprite PNG</a>
16
+ <h3>Preview (zoomed)</h3><canvas id="prev" width="384" height="512"></canvas></div>
17
+ <div class="card"><h3>The standard: Sir Reginald, 48×64, 15 colours, dark scheme, 977 bytes</h3>
18
+ <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAABACAYAAABcIPRGAAADmElEQVR4nO1av0sbURz/WDqEN8hVSgihlFKkiIM4lSAdgkMsDqVIp/4FHSR0EBFxuEmKlCLSQTqLdChSOgTMUDKIBIcOGTIUcXAIIYgNGYLbdbi++O7lzns/vpcm6AeO3Lt7L/f9vu/v7x0w4hhL+gGMOR4/73bb5M+7T/2HYSim0wCAnRbImRkIAwBQ63SQT6UwMz4OwGeGgonEVQjw1aiYTqPW6QSuV66urCVxz4oyTfDdFyHayNCBMcfjBDLmeGtPnnkiwYsTGU+cY4KB2UAYSpfN4bGBx0+n+3bxotkAADzMZHtjfn5+Vid59kBtgBNPCetdsDVCWy9EYgOmO8tVzAYkDFAQYgoSQ1pbfm2kRh8+fx8OL8SY4x2Vd/uuvyi8AwBE3UsiuTMCY4736+hrLyjJY/ne3u6Gt7e7QRKByd1osfHH6J4pyBnYyT4wumcK0lQiTNc5vnxapnxUDwONxElg5BlINBu9SaWocCcBDh604pCUMVtBDFJisAr7lQ/bZ5NJ4Lp10lKapzJXBWS5kCkDtvmQ1uJBdRB0mNJWoVV3MzDecteRL7wKXJt5FOz/cOyXfgfGF81G39pK+YcWPaRx4Plcrnd+clxFca6OJfc0kVqY4/bFgS13PfLeyXFVmwBdlZGhzYCtzsqQ1Uu3vr59KmS74zJsOxpaEuD+WVYjG/DAxlVJN7CNvArdMfC/MfIMkKQSUZ6pUvZ/k+ydGklA1ZUeuJM4cCeV5poyqc0Ad3MqBfuSe4ol91Tpf00bAGTZqBgboiQkpg1UahXLgG4Rw4nnklqcyHiA/044DLyC400B3U8TlCTwcXomMF6p15S7EBz5VAoV4SWfjFV3Ey8L8wCAeaGuiIMSAyv1WuwcVcMWVYernbyWvKR84/j5ytv3/pv2/W2/ZPzWbgUICSNGBP9WYqfVIsunEglkg3zzkngklt/Gyx982ELZjeayGexvN3vn1Uazd8+kRqCqK5QlUG00kctm+ogHrlstcsvlJpisCUOsrpo0s2Qb4LGAIywmiG40NzulbEOxEuh222PyAfiVFD+A61RAxYDzqVRgjdhu1MXIp9PaDIiNXFVQfBcUhdsngWGDtmhVvVKUJ4rKSk29kHY9IBLGmONFZZfnZ+2COC5dNhf+rTmk7FbrSiBAFGPOYdTEbre9EHb9pjU/j6vIzU7xdWUVgnQYKMRPIUcsEzpGrLQjhCCXQBQoJGO8OX8B8gyGB5O6YncAAAAASUVORK5CYII=" width="192" alt="Sir Reginald tiny sprite"></div>
19
+ <script>
20
+ function quantize(ctx,w,h,n){
21
+ const img=ctx.getImageData(0,0,w,h), d=img.data, buckets={};
22
+ for(let i=0;i<d.length;i+=4){ if(d[i+3]<128) continue;
23
+ const key=(d[i]>>4)+','+(d[i+1]>>4)+','+(d[i+2]>>4);
24
+ (buckets[key]=buckets[key]||[]).push([d[i],d[i+1],d[i+2]]); }
25
+ const pal=Object.values(buckets).sort((a,b)=>b.length-a.length).slice(0,n).map(g=>{
26
+ const m=[0,0,0]; g.forEach(p=>{m[0]+=p[0];m[1]+=p[1];m[2]+=p[2]}); return m.map(v=>Math.round(v/g.length)); });
27
+ for(let i=0;i<d.length;i+=4){ if(d[i+3]<128) continue;
28
+ let best=pal[0],bd=1e12; for(const p of pal){const dd=(d[i]-p[0])**2+(d[i+1]-p[1])**2+(d[i+2]-p[2])**2; if(dd<bd){bd=dd;best=p}}
29
+ d[i]=best[0];d[i+1]=best[1];d[i+2]=best[2]; }
30
+ ctx.putImageData(img,0,0);
31
+ }
32
+ document.getElementById('go').onclick=()=>{
33
+ const f=document.getElementById('file').files[0]; if(!f) return alert('Pick a picture first');
34
+ const [w,h]=document.getElementById('size').value.split('x').map(Number);
35
+ const n=+document.getElementById('cols').value;
36
+ const url=URL.createObjectURL(f), im=new Image();
37
+ im.onload=()=>{ const out=document.getElementById('out'); out.width=w; out.height=h;
38
+ const ctx=out.getContext('2d');
39
+ const s=Math.max(w/im.width,h/im.height), dw=im.width*s, dh=im.height*s;
40
+ ctx.drawImage(im,(w-dw)/2,(h-dh)/2,dw,dh);
41
+ quantize(ctx,w,h,n);
42
+ const prev=document.getElementById('prev'), pctx=prev.getContext('2d');
43
+ pctx.imageSmoothingEnabled=false; pctx.clearRect(0,0,prev.width,prev.height);
44
+ pctx.drawImage(out,0,0,prev.width,prev.height);
45
+ document.getElementById('dl').href=out.toDataURL('image/png'); };
46
+ im.src=url;
47
+ };
48
+ </script></body></html>