Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Frame 0 uses more than 256 color indexes #34

Open
DeanVanGreunen opened this issue Oct 26, 2021 · 4 comments
Open

Error: Frame 0 uses more than 256 color indexes #34

DeanVanGreunen opened this issue Oct 26, 2021 · 4 comments

Comments

@DeanVanGreunen
Copy link

Error: Frame 0 uses more than 256 color indexes

async function fixColors(filepath){
    return new Promise((resolve)=>{
        Jimp.read(filepath, function (err, test) {
            //what can i do here to fix the error?
            test.write(file); 
                 resolve();
        });        
    });
}
@DeanVanGreunen
Copy link
Author

DeanVanGreunen commented Oct 26, 2021

I'm using the above code to fix the colors, the error itself comes from this code

async function getFileBitmap(file){
    return new Promise((resolve)=>{
        Jimp.read(file)
        .then(image => {
            resolve(image.bitmap.data);
        })
    });
}


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

async function resizeImage(file, w, h){
    return new Promise((resolve)=>{
        Jimp.read(file, function (err, test) {
            test.resize(w, h)
                 .quality(50)                 
                 .write(file); 
                 resolve();
        });        
    });
}

here is the main function

async function mergeThumbnail(baseImage, gifImage, outputImage){
    return new Promise( async (resolve, reject)=>{
        const res = sizeOf(gifImage);
        const width = res.width, height = res.height;
        await resizeImage(baseImage, width, height);
        await fixColors(baseImage);
        const frames = [];
        let frame = new GifFrame(width, height, { delayCentisecs: 200 });
        frame.bitmap.data = await getFileBitmap(baseImage);
        frames.push(frame);
        let gif_frames = await getGifFrames(gifImage);
        gif_frames.forEach(frame => {
            frames.push(frame);
        });
        GifUtil.write(outputImage, frames);
        resolve();           
    });
}

@DeanVanGreunen
Copy link
Author

Hi @Giv0 Any ideas?

@mctrivia
Copy link

GifUtil.quantizeDekker(ouputImage,256);

@Grubba27
Copy link
Contributor

Grubba27 commented Nov 8, 2022

Solution above does work and if any of you want to see it in another example here is mine:

import { BitmapImage, GifCodec, GifFrame, GifUtil } from 'gifwrap';
import Jimp from 'jimp';
import { addLogoToImage } from './index';

const codec = new GifCodec();
export const addLogoToGif = async (buffer: Buffer): Promise<Buffer> => {
  const gif = await codec.decodeGif(buffer);

  const p = gif.frames.map(async (frame) => {
    const jimpImage = GifUtil.copyAsJimp(Jimp, frame);
    const buffer = await jimpImage.getBufferAsync(jimpImage.getMIME());
    const buffWithLogo = await addLogoToImage(buffer);
    const frameWithLogo = await Jimp.read(buffWithLogo);
    const bitmap = new BitmapImage(frameWithLogo.bitmap);
    GifUtil.quantizeDekker(bitmap, 256);
    return new GifFrame(bitmap);
  });
  const gifWithLogo = await Promise.all(p);
  const buf = await codec.encodeGif(gifWithLogo, { loops: 0 });
  return buf.buffer;
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants