-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-cover.js
More file actions
69 lines (61 loc) · 2.2 KB
/
Copy pathgenerate-cover.js
File metadata and controls
69 lines (61 loc) · 2.2 KB
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
import { createCanvas, loadFont, registerFont } from 'canvas';
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
try {
const canvas = createCanvas(1280, 1710);
const ctx = canvas.getContext('2d');
// Set background
ctx.fillStyle = '#faf8f3';
ctx.fillRect(0, 0, 1280, 1710);
// Set font (using system font as fallback)
ctx.font = 'bold 120px serif';
ctx.fillStyle = 'rgba(0, 0, 0, 0.15)';
ctx.textAlign = 'left';
ctx.textBaseline = 'top';
// Draw repeated "Angela Weigl" text
const text = 'Angela Weigl';
const positions = [
{ x: 50, y: 150, rot: -2 },
{ x: 450, y: 150, rot: 1 },
{ x: 850, y: 150, rot: -1 },
{ x: 250, y: 350, rot: 1.5 },
{ x: 650, y: 350, rot: -1.5 },
{ x: 1050, y: 350, rot: 0.5 },
{ x: 50, y: 550, rot: -0.5 },
{ x: 450, y: 550, rot: 2 },
{ x: 850, y: 550, rot: -1 },
{ x: 250, y: 750, rot: 1 },
{ x: 650, y: 750, rot: -2 },
{ x: 1050, y: 750, rot: 0.5 },
{ x: 50, y: 950, rot: -1.5 },
{ x: 450, y: 950, rot: 1 },
{ x: 850, y: 950, rot: -0.5 },
{ x: 250, y: 1150, rot: 0.5 },
{ x: 650, y: 1150, rot: -1 },
{ x: 1050, y: 1150, rot: 1.5 },
{ x: 50, y: 1350, rot: -2 },
{ x: 450, y: 1350, rot: 1 },
{ x: 850, y: 1350, rot: -1 },
{ x: 250, y: 1550, rot: 1.5 },
{ x: 650, y: 1550, rot: -1.5 },
{ x: 1050, y: 1550, rot: 0.5 },
];
positions.forEach(pos => {
ctx.save();
ctx.translate(pos.x, pos.y);
ctx.rotate(pos.rot * Math.PI / 180);
ctx.fillText(text, 0, 0);
ctx.restore();
});
// Save as PNG
const buffer = canvas.toBuffer('image/png');
fs.writeFileSync(path.join(__dirname, 'public', 'textures', 'book-cover.png'), buffer);
console.log('Successfully generated book-cover.png!');
} catch (error) {
console.log('Error:', error.message);
console.log('Please install canvas: npm install canvas');
console.log('Or open generate-cover.html in your browser to download the PNG');
}