jimp-dev / gifwrap

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

Invalid settings when resizing Jimp image created from a BitmapImage. #8

Closed dcerisano closed 5 years ago

dcerisano commented 6 years ago

I had an issue with your BitmapImage class. Jimp images created from it would not resize.

var width  = 30;
var height = 1;
var images = [];

GifUtil.read(path.join(__dirname + "/../images/default.gif")).then(inputGif => {
    for (var frame = 0; frame<inputGif.frames.length; frame++){
        images[frame] = new Jimp(1, 1 ,0);
        images[frame].bitmap =  new BitmapImage(inputGif.frames[frame]);
        images[frame].resize(width, height); // ERROR INVALID RESIZE SETTINGS
    }
});

I simply am not using it now, instead opting for the following method, which works.

var width  = 30;
var height = 1;
var images = [];

GifUtil.read(path.join(__dirname + "/../images/default.gif")).then(inputGif => {
    images = [];
    for (var frame = 0; frame<inputGif.frames.length; frame++){
        images[frame] = new Jimp(inputGif.frames[frame].bitmap.width, inputGif.frames[frame].bitmap.height ,0);
        images[frame].bitmap.data = inputGif.frames[frame].bitmap.data;
        images[frame].resize(width, height); // WORKS
    }
});

default.gif

jtlapp commented 5 years ago

Okay, thank you, I've confirmed the problem. There appears to be an unexpected incompatibility with Jimp.

jtlapp commented 5 years ago

I resolved this by adding the methods GifUtil.copyAsJimp() and GifUtil.shareAsJimp(), which behave as macros for working with Jimp images.