오윤석

gif render

......@@ -7,12 +7,16 @@ class GifGenerator {
this.canvas = canvas;
this.width = canvas.getWidth();
this.height = canvas.getHeight();
this.gif = new GIF(this.width, this.height);
this.gif.start();
this._initializeGif();
}
_initializeGif() {
this.gif = new GIF(this.width, this.height);
this.gif.setTransparent(null);
this.gif.setRepeat(0);
this.gif.setQuality(10);
this.gif.start();
}
_addFrame(delay = 0) {
......@@ -28,6 +32,8 @@ class GifGenerator {
}
make() {
this._initializeGif();
const fabricObjs = this.canvas.getObjects();
const objs = [];
......@@ -41,33 +47,41 @@ class GifGenerator {
}
});
if (objs.length > 0) {
let objIdx = 0;
let isAddMode = true;
const draw = () => {
const obj = objs[objIdx];
if (isAddMode) {
const fabricObj = obj.getCurrentFabricObject();
obj.next();
if (obj.end()) {
if (objIdx < objs.length - 1) objIdx++;
else this.canvas.off("after:render", draw);
} else {
return new Promise((resolve, reject) => {
if (objs.length > 0) {
let objIdx = 0;
let isAddMode = true;
const draw = () => {
const obj = objs[objIdx];
if (isAddMode) {
const fabricObj = obj.getCurrentFabricObject();
obj.next();
isAddMode = false;
this.canvas.add(fabricObj);
} else {
this._addFrame(1);
isAddMode = true;
if (obj.end()) {
if (objIdx < objs.length - 1) {
objIdx++;
draw();
} else {
this.canvas.off("after:render", draw);
resolve(this._render());
}
} else {
this.canvas.remove(
this.canvas._objects[this.canvas._objects.length - 1]
);
}
}
this.canvas.add(fabricObj);
} else {
this.canvas.remove(
this.canvas._objects[this.canvas._objects.length - 1]
);
isAddMode = true;
}
};
this.canvas.on("after:render", draw);
draw();
}
console.log(objs);
};
this.canvas.on("after:render", draw);
draw();
} else {
reject(new Error("no objects"));
}
});
}
}
......