glitch-canvas
glitch-canvas copied to clipboard
I'm getting some errors while using glitch-canvas
Hi, I'm using this module for my bot made in discord.js, and sometimes I get random errors like
Error: Invalid component ID 33 in SOS
Error: Invalid component ID 12 in SOS
Error: Bogus marker length
Error: Huffman table 0x03 was not defined
My code is:
const Discord = require('discord.js')
const Canvas = require('canvas')
const fs = require('fs')
const db = require('megadb')
const bsonDB = require("bsondb");
const { createCanvas, loadImage } = require('canvas');
const request = require('node-superfetch');
const glitch = require('glitch-canvas')
module.exports = {
name: 'glitch',
description: '',
async execute(client, message, args) {
let user = message.mentions.members.first() || message.guild.members.cache.get(args[0]) || message.member
let image = user.user.displayAvatarURL({ format: 'jpeg', size: 1024 }) //url below
const { body } = await request.get(image);
const data = await loadImage(body);
const canvas = createCanvas(data.width < 250 ? 278 : data.width, data.height < 250 ? 278 : data.height); //using this because I think it happens with small images
const ctx = canvas.getContext('2d');
ctx.drawImage(data, 0, 0, canvas.width, canvas.height);
const attachment = canvas.toBuffer();
glitch({ seed: Math.floor(Math.random() * 20), itinerations: Math.floor(Math.random() * 20), amount: Math.floor(Math.random() * 20) })
.fromBuffer(attachment)
.toBuffer()
.then(function(glitchedBuffer) {
message.channel.send({
files: [{
attachment: glitchedBuffer,
name: 'glitch.jpeg'
}]
})
}).catch(error => {
message.channel.send('Please, use the command another time. ' + error)
})
}
}
Currently I'm using this image
Thanks in advance
hey @kevin2005015, thank you for reporting this issue. It's great to see the library being used in other projects.
I've encountered similar issues in the past and was unable to fix them entirely, but I'll have another look. This might take a while though.
Any chance you could add the exact parameters that were used when the error occurs? This would make reproducing the issue so much easier.
Thanks again!
Hello again,
I tried logging the parameters, and I got some which happens everytime:
Seed 11, 12 itinerations, 15 amount, 84 quality (I checked this and happens everytime with the same error Unsupported marker type 0x26
Seed 19, 12 itinerations, 11 amount, 48 quality Error: Unsupported marker type 0x1c
Seed 1, 11 itinerations, 8 amount, 88 quality Error: Invalid component ID 20 in SOS
I got all these in a lot of attemps, so it doesn't happen usually.
Best regards
Edit: It only happens while using glitch-canvas, I tried in your website and it worked fine