jimp-dev / gifwrap

A Jimp-compatible library for working with GIFs
MIT License
73 stars 17 forks source link

GifError: Invalid block size #41

Open DeanVanGreunen opened 2 years ago

DeanVanGreunen commented 2 years ago

Hi, occasionally I'm getting this error, i think it had to do with GifUtil

GifError: Invalid block size
at new GifReader (/var/www/gifier/node_modules/omggif/omggif.js:489:41)
at GifCodec.decodeGif (/var/www/gifier/node_modules/gifwrap/src/gifcodec.js:55:26)
at /var/www/gifier/node_modules/gifwrap/src/gifutil.js:222:24

here is my code blocks

getGifFrames

async function getGifFrames(file){
    return new Promise((resolve)=>{
        GifUtil.read(file).then(inputGif => {
            resolve(inputGif.frames);
        });         
    });
}

mergeThumbnail

async function mergeThumbnail(text, gifImage, outputImage, playIcon){
    return new Promise( async (resolve, reject)=>{
        const font = await Jimp.loadFont(Jimp.FONT_SANS_32_BLACK);
        const font2 = await Jimp.loadFont(Jimp.FONT_SANS_32_WHITE);
        const res = sizeOf(gifImage);
        const width = res.width, height = res.height;
        let frames = [];
        let gif_frames = [];
        try {
        gif_frames = await getGifFrames(gifImage);        
        } catch(e13){
            reject(false);
        }
        const sec_img = (await Jimp.read(playIcon)).resize(48, 48);  
        let w = (width / 2) - (sec_img.bitmap.width / 2);
        let h = (height / 2) - (sec_img.bitmap.height / 2);
        let x = 0;
        let y = height - 56;
        let maxWidth = 320;    

        gif_frames.forEach((frame) => {
            let image = new Jimp(frame.bitmap.width, frame.bitmap.height);
            image.bitmap = frame.bitmap;            
            image.blit(sec_img, 136, 156, 0, 0, 48, 48); 
            // do stuff here (shortned)
            GifUtil.quantizeDekker(image);

            frames.push(new GifFrame(new BitmapImage(image.bitmap)));
        });        

        GifUtil.write(outputImage, frames);
        resolve(outputImage);           
    });
}