1
+ // Should generate a skin 3D render based on the uuid
2
+
1
3
const express = require ( 'express' ) ;
2
4
const { createCanvas, loadImage } = require ( 'canvas' ) ;
3
5
const fetch = require ( 'node-fetch' ) ;
@@ -9,103 +11,103 @@ app.get('/assets/frozenblock/render/skin.png', async (req, res) => {
9
11
const uuid = req . query . uuid ;
10
12
11
13
if ( ! uuid ) {
12
- res . status ( 400 ) . send ( 'UUID non fornito ' ) ;
14
+ res . status ( 400 ) . send ( 'UUID not found ' ) ;
13
15
return ;
14
16
}
15
17
16
18
try {
17
- // Carica la skin di Minecraft usando l'UUID
19
+ // Fetch UUID from mojang
18
20
const response = await fetch ( `https://sessionserver.mojang.com/session/minecraft/profile/${ uuid } ` ) ;
19
21
const data = await response . json ( ) ;
20
22
const textures = data . properties . find ( prop => prop . name === "textures" ) ;
21
23
22
24
if ( ! textures ) {
23
- res . status ( 404 ) . send ( 'Texture non trovata per l\'UUID fornito ' ) ;
25
+ res . status ( 404 ) . send ( 'Texture not found for given UUID ' ) ;
24
26
return ;
25
27
}
26
28
27
29
const textureData = JSON . parse ( Buffer . from ( textures . value , 'base64' ) . toString ( 'utf-8' ) ) ;
28
30
const skinUrl = textureData [ 'textures' ] [ 'SKIN' ] [ 'url' ] ;
29
31
30
- // Crea un canvas con dimensioni 360x864
32
+ // Create a 360x864 canvas
31
33
const width = 360 ;
32
34
const height = 864 ;
33
35
const canvas = createCanvas ( width , height ) ;
34
36
const ctx = canvas . getContext ( '2d' ) ;
35
37
36
- // Imposta lo sfondo trasparente
38
+ // Set the background to transparent
37
39
ctx . clearRect ( 0 , 0 , width , height ) ;
38
40
39
- // Carica l'immagine della skin
41
+ // Load Skin image
40
42
const skinImage = await loadImage ( skinUrl ) ;
41
43
42
- // Imposta il filtro "nearest neighbor" per un effetto pixelato
44
+ // sets Nearest Neighbor
43
45
ctx . imageSmoothingEnabled = false ;
44
46
45
- const scale = 20 ; // Scala per ingrandire il rombo
47
+ const scale = 20 ; // Scale image
46
48
47
- // Centro della testa
49
+ // Middle of head
48
50
const centerX = width / 2 ;
49
- const topMargin = 100 ; // Spostamento verticale
51
+ const topMargin = 100 ; // Vertical translation
50
52
51
- // === Prima faccia (frontale) ===
53
+ // === First face ===
52
54
const frontSx = 8 ;
53
55
const frontSy = 8 ;
54
56
const sWidth = 8 ;
55
57
const sHeight = 8 ;
56
58
57
- // Trasformazione isometrica per la prima faccia (frontale)
59
+ // Isometric transform for first face
58
60
ctx . setTransform ( 1 , 0.5 , 0 , 1 , centerX - ( sWidth * scale ) / 2 - 90 , topMargin ) ;
59
- // Ombreggiatura per la faccia frontale (nessuna modifica)
61
+ // Shadow for first face
60
62
ctx . drawImage ( skinImage , frontSx , frontSy , sWidth , sHeight , 0 , 0 , sWidth * scale , sHeight * scale ) ;
61
63
62
- // Ripristina la trasformazione originale
64
+ // Reset transformations
63
65
ctx . setTransform ( 1 , 0 , 0 , 1 , 0 , 0 ) ;
64
66
65
- // === Seconda faccia (laterale destra) ===
67
+ // === Second face ===
66
68
const rightSx = 16 ;
67
69
const rightSy = 8 ;
68
70
69
- // Trasformazione isometrica per la seconda faccia (laterale destra)
71
+ // Isometric transform for second face
70
72
ctx . setTransform ( 1 , - 0.5 , 0 , 1 , centerX + ( sWidth * scale ) / 2 - scale - 70 , topMargin + 80 ) ;
71
- // Ombreggiatura per la faccia laterale (leggermente più scura)
73
+ // Shadow for second face
72
74
ctx . drawImage ( skinImage , rightSx , rightSy , sWidth , sHeight , 0 , 0 , sWidth * scale , sHeight * scale ) ;
73
- ctx . globalAlpha = 1.0 ; // Ripristina opacità per le altre facce
75
+ ctx . globalAlpha = 1.0 ; // Resets opacity for other faces
74
76
75
- // Ripristina la trasformazione originale
77
+ // Reset transformations
76
78
ctx . setTransform ( 1 , 0 , 0 , 1 , 0 , 0 ) ;
77
79
78
- // === Terza faccia (superiore) ===
80
+ // === Third face ===
79
81
const topSx = 8 ;
80
82
const topSy = 0 ;
81
83
82
- // Trasformazione isometrica per la faccia superiore (ruotata e traslata sopra le altre facce)
84
+ // Isometric transform for third face
83
85
ctx . setTransform ( 1 , 0.5 , - 1 , 0.5 , centerX - scale / 2 , topMargin - ( sHeight * scale ) / 2 ) ;
84
- // Ombreggiatura per la faccia superiore (ancora più scura)
86
+ // Shadow for third face
85
87
ctx . drawImage ( skinImage , topSx , topSy , sWidth , sHeight , 0 , 0 , sWidth * scale , sHeight * scale ) ;
86
- ctx . globalAlpha = 1.0 ; // Ripristina opacità
88
+ ctx . globalAlpha = 1.0 ; // Resets opacity for other faces
87
89
88
- // Ripristina la trasformazione originale
90
+ // Reset transformations
89
91
ctx . setTransform ( 1 , 0 , 0 , 1 , 0 , 0 ) ;
90
92
91
- // Imposta l'intestazione della risposta
93
+ // Sets the header
92
94
res . setHeader ( 'Content-Type' , 'image/png' ) ;
93
95
94
- // Invia l'immagine generata come risposta
96
+ // Sends the image as response
95
97
canvas . toBuffer ( ( err , buf ) => {
96
98
if ( err ) {
97
- res . status ( 500 ) . send ( 'Errore nella generazione dell\'immagine ' ) ;
99
+ res . status ( 500 ) . send ( 'Generating skin image error ' ) ;
98
100
return ;
99
101
}
100
102
res . end ( buf ) ;
101
103
} ) ;
102
104
103
105
} catch ( error ) {
104
- console . error ( 'Errore nel caricamento della skin:' , error ) ;
105
- res . status ( 500 ) . send ( 'Errore nel caricamento della skin' ) ;
106
+ console . error ( 'Loading skin error :' , error ) ;
107
+ res . status ( 500 ) . send ( 'Loading skin error ' ) ;
106
108
}
107
109
} ) ;
108
110
109
111
app . listen ( port , ( ) => {
110
- console . log ( `Server in ascolto su http://localhost:${ port } ` ) ;
112
+ // console.log(`Server listening to http://localhost:${port}`);
111
113
} ) ;
0 commit comments