Draw each character with random y-offset

This commit is contained in:
ExtrasContainer
2024-02-04 21:13:35 +00:00
parent 948cd94573
commit 5d91066bf1
+14 -1
View File
@@ -45,7 +45,19 @@ module.exports = {
ctx.textBaseline = 'middle'; ctx.textBaseline = 'middle';
ctx.textAlign = 'center'; ctx.textAlign = 'center';
ctx.fillStyle = '#ffffff'; ctx.fillStyle = '#ffffff';
ctx.fillText(captcha, 100, 37.5);
// Calculate spacing between characters to fit within canvas width
const charWidth = 30;
const totalWidth = captcha.length * charWidth;
const startX = (canvas.width - totalWidth) / 2;
// Draw each character with random y-offset
for (let i = 0; i < captcha.length; i++) {
const x = startX + i * charWidth + charWidth / 2; // Adjust x-position for each character
const y = 37.5 + Math.random() * 30 - 15; // Random y-offset
ctx.fillText(captcha[i], x, y);
}
// Adding noise // Adding noise
for (let i = 0; i < 50; i++) { for (let i = 0; i < 50; i++) {
@@ -81,6 +93,7 @@ module.exports = {
return buffer; return buffer;
} }
if (interaction.channel.id !== cfg.guilds[guildId].channelId) { if (interaction.channel.id !== cfg.guilds[guildId].channelId) {
return interaction.reply({ content: cfg.messages.wrongChannel, ephemeral: true }) return interaction.reply({ content: cfg.messages.wrongChannel, ephemeral: true })
} }