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

Frame 0 uses more than 256 color indexes #12

Closed
redserpent7 opened this issue Sep 2, 2018 · 6 comments
Closed

Frame 0 uses more than 256 color indexes #12

redserpent7 opened this issue Sep 2, 2018 · 6 comments
Labels

Comments

@redserpent7
Copy link

I am not sure how or why this is happening. I am loading an existing Gif, resizing it one frame at a time with Jimp and then saving the output gif in a file.

I am not sure at which point or why the palette changes since my source image is indeed a GIF.

This is my code:

GifUtil.read("org.gif").then(inputGif => {
    images = [];
    
	for (var frame = 0; frame<inputGif.frames.length; frame++){
		var j = new Jimp(inputGif.frames[frame].bitmap.width, inputGif.frames[frame].bitmap.height , 0);
        j.bitmap.data = inputGif.frames[frame].bitmap.data;
        j.resize(width, height);
       
        images[frame] = new GifFrame(j.bitmap);
    }

    inputGif.frames = images;
   

    return GifUtil.write("modified.gif", inputGif.frames, inputGif).then(outputGif => {
        console.log("modified");
    });
});

How do I prevent it from up-scaling the color palette? or how can I quantize the frame?

@jtlapp
Copy link
Collaborator

jtlapp commented Sep 2, 2018

Please ping me again next week, unless you resolve this on your own. I'm in the middle of moving, don't have time to investigate. Sorry about that!

@jtlapp
Copy link
Collaborator

jtlapp commented Sep 2, 2018

Oh, Jimp add colors when resizing. Call one of the quantize*() methods to reduce the number of colors again.

@redserpent7
Copy link
Author

Oh I never saw the quantize methods. thanks.

@DeanVanGreunen
Copy link

@redserpent7 I have a similar issue here could you assist please?

@oluSammy
Copy link

@redserpent7 pls how did you used the quantize method

@DeanVanGreunen
Copy link

@oluSammy take a look at my code, taken from my live production server. it simply does the following

  1. load gif file
  2. extract frames from the gif
  3. edit each gif frame
  4. quantize the frame
  5. append the frame to a new frame list
  6. write frames to output file
// Helper functions
async function getGifFrames(file) {
  return new Promise((resolve) => {
    GifUtil.read(file).then((inputGif) => {
      resolve(inputGif.frames);
    });
  });
}


// Sample Code

let frames = []; // store new edited frames
let gif_frames = await getGifFrames("myImage.gif"); // get the frames from an existing GiF

gif_frames.forEach((frame) => {
 let newFrame = editFrame(frame); // edit frame here
 GifUtil.quantizeDekker(newFrame); // quantize the image
 frames.push(new GifFrame(new BitmapImage(image.bitmap))); // push frame to new frame list
});

// do something with the frame list like saving to disc
GifUtil.write("outputImage.gif", frames);

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

No branches or pull requests

4 participants