-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSoulsBannerGeneratorPage.jsx
More file actions
455 lines (418 loc) · 15.5 KB
/
SoulsBannerGeneratorPage.jsx
File metadata and controls
455 lines (418 loc) · 15.5 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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
import React, { useState, useRef, useEffect, useCallback } from 'react';
import { Link } from 'react-router-dom';
import {
ArrowLeftIcon,
DownloadSimpleIcon,
ImageIcon,
TextTIcon,
PaletteIcon,
SlidersHorizontalIcon,
} from '@phosphor-icons/react';
import { useToast } from '../../hooks/useToast';
import Seo from '../../components/Seo';
import BreadcrumbTitle from '../../components/BreadcrumbTitle';
import CustomSlider from '../../components/CustomSlider';
import CustomToggle from '../../components/CustomToggle';
import CustomColorPicker from '../../components/CustomColorPicker';
import CustomDropdown from '../../components/CustomDropdown';
const PRESETS = {
YOU_DIED: {
text: 'YOU DIED',
textColor: '#9d0a0a',
glowColor: '#ff0000',
fontSize: 120,
fontFamily: 'Cinzel',
fontWeight: 400,
letterSpacing: 10,
overlayOpacity: 0.5,
},
ENEMY_FELLED: {
text: 'ENEMY FELLED',
textColor: '#e8c227', // Gold-ish
glowColor: '#ffea00',
fontSize: 100,
fontFamily: 'Cinzel',
fontWeight: 700,
letterSpacing: 5,
overlayOpacity: 0.4,
},
BONFIRE_LIT: {
text: 'BONFIRE LIT',
textColor: '#ffb347',
glowColor: '#ff8c00',
fontSize: 100,
fontFamily: 'Cinzel',
fontWeight: 400,
letterSpacing: 5,
overlayOpacity: 0.4,
},
WASTED: {
text: 'WASTED',
textColor: '#9d0a0a', // GTA style red
glowColor: '#000000',
fontSize: 120,
fontFamily: 'Pricedown', // Fallback to sans-serif if not available
fontWeight: 900,
letterSpacing: 2,
overlayOpacity: 0.5,
},
};
const FONT_OPTIONS = [
{ value: 'Cinzel', label: 'Cinzel (Souls)' },
{ value: 'Space Mono', label: 'Space Mono' },
{ value: 'JetBrains Mono', label: 'JetBrains Mono' },
{ value: 'Playfair Display', label: 'Playfair Display' },
{ value: 'Arvo', label: 'Arvo' },
{ value: 'Syne', label: 'Syne' },
{ value: 'Outfit', label: 'Outfit' },
{ value: 'IBM Plex Mono', label: 'IBM Plex Mono' },
{ value: 'Instrument Serif', label: 'Instrument Serif' },
{ value: 'Instrument Sans', label: 'Instrument Sans' },
{ value: 'Nunito', label: 'Nunito' },
{ value: 'VT323', label: 'VT323 (Retro)' },
{ value: 'Brush Script MT', label: 'Brush Script' },
{ value: 'Courier New', label: 'Courier New' },
];
function SoulsBannerGeneratorPage() {
const { addToast } = useToast();
const [image, setImage] = useState(null);
const canvasRef = useRef(null);
// Configuration State
const [text, setText] = useState(PRESETS.ENEMY_FELLED.text);
const [fontSize, setFontSize] = useState(PRESETS.ENEMY_FELLED.fontSize);
const [textColor, setTextColor] = useState(PRESETS.ENEMY_FELLED.textColor);
const [glowColor, setGlowColor] = useState(PRESETS.ENEMY_FELLED.glowColor);
const [overlayOpacity, setOverlayOpacity] = useState(
PRESETS.ENEMY_FELLED.overlayOpacity,
);
const [letterSpacing, setLetterSpacing] = useState(
PRESETS.ENEMY_FELLED.letterSpacing,
);
const [yOffset, setYOffset] = useState(50); // Percentage from top
const [showOverlay, setShowOverlay] = useState(true);
const [fontFamily, setFontFamily] = useState('Cinzel');
const [fontWeight, setFontWeight] = useState(PRESETS.ENEMY_FELLED.fontWeight);
useEffect(() => {
// Load Cinzel font
const link = document.createElement('link');
link.href =
'https://fonts.googleapis.com/css2?family=Cinzel:wght@400;700;900&display=swap';
link.rel = 'stylesheet';
document.head.appendChild(link);
return () => document.head.removeChild(link);
}, []);
const handleImageUpload = (e) => {
const file = e.target.files[0];
const reader = new FileReader();
reader.onload = (event) => {
setImage(event.target.result);
};
if (file) reader.readAsDataURL(file);
};
const drawCanvas = useCallback(() => {
if (!image || !canvasRef.current) return;
const canvas = canvasRef.current;
const ctx = canvas.getContext('2d');
const img = new Image();
img.crossOrigin = 'anonymous';
img.src = image;
img.onload = () => {
// Set canvas to image dimensions
canvas.width = img.width;
canvas.height = img.height;
// Draw original image
ctx.drawImage(img, 0, 0);
// Draw Overlay Band
if (showOverlay) {
const bandHeight = fontSize * 2.5;
const yPos = (canvas.height * yOffset) / 100;
// Gradient for the band
const gradient = ctx.createLinearGradient(
0,
yPos - bandHeight / 2,
0,
yPos + bandHeight / 2,
);
gradient.addColorStop(0, 'rgba(0,0,0,0)');
gradient.addColorStop(0.2, `rgba(0,0,0,${overlayOpacity})`);
gradient.addColorStop(0.8, `rgba(0,0,0,${overlayOpacity})`);
gradient.addColorStop(1, 'rgba(0,0,0,0)');
ctx.fillStyle = gradient;
ctx.fillRect(0, yPos - bandHeight / 2, canvas.width, bandHeight);
}
// Draw Text
ctx.save();
ctx.font = `${fontWeight} ${fontSize}px "${fontFamily}", serif`;
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
const textX = canvas.width / 2;
const textY = (canvas.height * yOffset) / 100;
// Glow/Shadow
ctx.shadowColor = glowColor;
ctx.shadowBlur = 20;
ctx.fillStyle = textColor;
// Text drawing with spacing manually
if (letterSpacing > 0) {
const totalWidth =
ctx.measureText(text).width + (text.length - 1) * letterSpacing;
let currentX = textX - totalWidth / 2;
for (let i = 0; i < text.length; i++) {
const char = text[i];
ctx.fillText(char, currentX, textY);
currentX += ctx.measureText(char).width + letterSpacing;
}
} else {
ctx.fillText(text, textX, textY);
}
ctx.restore();
};
}, [
image,
text,
fontSize,
textColor,
glowColor,
overlayOpacity,
yOffset,
showOverlay,
letterSpacing,
fontFamily,
fontWeight,
]);
useEffect(() => {
drawCanvas();
// Re-draw when font loads (a bit hacky but works for now)
document.fonts.ready.then(drawCanvas);
}, [drawCanvas]);
const handleDownload = () => {
if (canvasRef.current) {
const canvas = canvasRef.current;
const link = document.createElement('a');
link.download = `souls-banner-${Date.now()}.png`;
link.href = canvas.toDataURL('image/png');
link.click();
addToast({
title: 'Success',
message: 'Banner image generated and downloaded.',
type: 'success',
});
}
};
const applyPreset = (key) => {
const p = PRESETS[key];
setText(p.text);
setTextColor(p.textColor);
setGlowColor(p.glowColor);
setFontSize(p.fontSize);
setFontFamily(p.fontFamily);
setFontWeight(p.fontWeight);
setLetterSpacing(p.letterSpacing);
setOverlayOpacity(p.overlayOpacity);
};
return (
<div className="min-h-screen bg-[#0a0a0a] text-gray-100 font-sans selection:bg-red-900/50 selection:text-white">
<Seo
title="Souls Banner Generator | Fezcodex"
description="Generate Dark Souls style 'Enemy Felled' banners on your images."
keywords={['dark souls', 'generator', 'meme', 'banner', 'image editor']}
/>
<div className="mx-auto max-w-7xl px-6 py-24 md:px-12">
{/* Header */}
<header className="mb-16">
<Link
to="/apps"
className="mb-8 inline-flex items-center gap-2 text-xs font-mono text-gray-500 hover:text-red-500 transition-colors uppercase tracking-widest"
>
<ArrowLeftIcon weight="bold" />
<span>Applications</span>
</Link>
<div className="flex flex-col md:flex-row md:items-end justify-between gap-8">
<div className="space-y-4">
<BreadcrumbTitle
title="Souls Banner"
slug="souls-gen"
variant="brutalist"
/>
<p className="text-xl text-gray-400 max-w-2xl font-serif italic">
"The flow of time itself is convoluted; with heroes centuries
old phasing in and out."
</p>
</div>
<label
htmlFor="image-upload"
className="group relative inline-flex items-center gap-3 px-8 py-4 bg-white text-black hover:bg-red-600 hover:text-white transition-all duration-300 font-mono uppercase tracking-widest text-sm font-black rounded-sm cursor-pointer shadow-[4px_4px_0px_rgba(255,255,255,0.2)] hover:shadow-none translate-x-[-4px] translate-y-[-4px] hover:translate-x-0 hover:translate-y-0"
>
<ImageIcon weight="bold" size={20} />
<span>Upload Image</span>
<input
id="image-upload"
type="file"
accept="image/*"
onChange={handleImageUpload}
className="hidden"
/>
</label>
</div>
</header>
<div className="grid grid-cols-1 lg:grid-cols-12 gap-12">
{/* Controls */}
<div className="lg:col-span-4 space-y-8 h-fit lg:sticky lg:top-8">
{/* Presets */}
<div className="bg-[#111] border border-white/5 p-6 rounded-sm space-y-4">
<h3 className="font-mono text-[10px] font-bold text-gray-500 uppercase tracking-widest flex items-center gap-2">
<SlidersHorizontalIcon weight="fill" />
Presets
</h3>
<div className="grid grid-cols-2 gap-2">
{Object.keys(PRESETS).map((key) => (
<button
key={key}
onClick={() => applyPreset(key)}
className="px-4 py-2 border border-white/10 hover:border-red-500/50 hover:bg-red-900/10 text-xs font-mono text-gray-400 hover:text-red-400 transition-all uppercase"
>
{PRESETS[key].text}
</button>
))}
</div>
</div>
{/* Text Config */}
<div className="bg-[#111] border border-white/5 p-6 rounded-sm space-y-6">
<h3 className="font-mono text-[10px] font-bold text-gray-500 uppercase tracking-widest flex items-center gap-2">
<TextTIcon weight="fill" />
Text Configuration
</h3>
<div className="space-y-2">
<label className="text-xs font-mono text-gray-500 uppercase">
Message
</label>
<input
type="text"
value={text}
onChange={(e) => setText(e.target.value.toUpperCase())}
className="w-full bg-black border border-white/10 px-4 py-3 text-white font-serif tracking-widest focus:border-red-500 outline-none transition-colors"
/>
</div>
<div className="space-y-4">
<CustomDropdown
label="Font Family"
options={FONT_OPTIONS}
value={fontFamily}
onChange={setFontFamily}
variant="brutalist"
icon={TextTIcon}
/>
<CustomSlider
variant="brutalist"
label="Font Weight"
min={100}
max={900}
step={100}
value={fontWeight}
onChange={(val) => setFontWeight(val)}
/>
<CustomSlider
variant="brutalist"
label="Font Size"
min={20}
max={400}
value={fontSize}
onChange={(val) => setFontSize(val)}
/>
<CustomSlider
variant="brutalist"
label="Letter Spacing"
min={0}
max={50}
value={letterSpacing}
onChange={(val) => setLetterSpacing(val)}
/>
<CustomSlider
variant="brutalist"
label="Vertical Position"
min={0}
max={100}
value={yOffset}
onChange={(val) => setYOffset(val)}
/>
</div>
</div>
{/* Visuals */}
<div className="bg-[#111] border border-white/5 p-6 rounded-sm space-y-6">
<h3 className="font-mono text-[10px] font-bold text-gray-500 uppercase tracking-widest flex items-center gap-2">
<PaletteIcon weight="fill" />
Visuals
</h3>
<div className="grid grid-cols-1 gap-4">
<CustomColorPicker
label="Text Color"
value={textColor}
onChange={setTextColor}
variant="brutalist"
/>
<CustomColorPicker
label="Glow Color"
value={glowColor}
onChange={setGlowColor}
variant="brutalist"
/>
</div>
<div className="pt-4 border-t border-white/5 space-y-4">
<CustomSlider
variant="brutalist"
label="Overlay Opacity"
min={0}
max={1}
step={0.1}
value={overlayOpacity}
onChange={(val) => setOverlayOpacity(val)}
/>
<div className="flex items-center justify-between">
<span className="text-xs font-mono text-gray-500 uppercase">
Show Overlay Band
</span>
<CustomToggle
variant="brutalist"
checked={showOverlay}
onChange={() => setShowOverlay(!showOverlay)}
/>
</div>
</div>
</div>
</div>
{/* Preview */}
<div className="lg:col-span-8">
<div className="relative border border-white/10 bg-[#000] p-4 rounded-sm">
{image ? (
<div className="relative w-full flex flex-col items-center">
<canvas
ref={canvasRef}
className="max-w-full h-auto shadow-2xl"
/>
<div className="mt-6 w-full flex justify-end">
<button
onClick={handleDownload}
className="flex items-center gap-3 px-8 py-4 bg-white text-black font-black uppercase tracking-[0.2em] hover:bg-red-500 hover:text-white transition-all text-xs"
>
<DownloadSimpleIcon weight="bold" size={18} />
<span>Save Image</span>
</button>
</div>
</div>
) : (
<div className="aspect-video w-full border border-white/10 border-dashed rounded-sm flex flex-col items-center justify-center text-center gap-4 bg-[#050505]">
<div className="w-16 h-16 rounded-full bg-white/5 flex items-center justify-center text-gray-600">
<ImageIcon size={32} />
</div>
<p className="font-mono text-xs uppercase tracking-[0.2em] text-gray-500">
Upload an image to begin
</p>
</div>
)}
</div>
</div>
</div>
</div>
</div>
);
}
export default SoulsBannerGeneratorPage;