Как получить gif-кадры с помощью Node GraphicsMagick/ImageMagick

#imagemagick #graphicsmagick #gm

Вопрос:

Как получить gif-кадры с помощью node gm?

Пример на PHP

 $frames = new Imagick( 'image.gif' )->coalesceImages();
 

https://github.com/aheckmann/gm

Ответ №1:

https://github.com/aheckmann/gm/issues/512

 gm("./image.gif").identify(function (err, val) {
    let frames_count = val.Scene.replace(/d* of /, "");

    for(let i = 0; i < frames_count; i  ) {
        let path = `./frame${i}.png`;
        this.selectFrame(i).write(path, function () {
            console.log(arguments[3]);
        });
    }
});