Fixed delay for delays smaller or equal to 1
This commit is contained in:
parent
0176bd063f
commit
d918e240bd
1 changed files with 8 additions and 1 deletions
|
@ -52,8 +52,10 @@ class ImageEx {
|
||||||
const reader = new GifReader(new Uint8Array(this.data));
|
const reader = new GifReader(new Uint8Array(this.data));
|
||||||
this.width = reader.width;
|
this.width = reader.width;
|
||||||
this.height = reader.height;
|
this.height = reader.height;
|
||||||
|
console.log('Decoding frames');
|
||||||
this.frames = this.decodeFrames(reader);
|
this.frames = this.decodeFrames(reader);
|
||||||
|
|
||||||
|
console.log('Frames decoded!');
|
||||||
this.renderAllFrames();
|
this.renderAllFrames();
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
@ -165,6 +167,11 @@ class CanvasEx {
|
||||||
if ((actualDelay === undefined || actualDelay === null)
|
if ((actualDelay === undefined || actualDelay === null)
|
||||||
&& (delay === undefined || delay === null)) throw new Error('Delay has to be set!');
|
&& (delay === undefined || delay === null)) throw new Error('Delay has to be set!');
|
||||||
const canvas = createCanvas(this.width, this.height);
|
const canvas = createCanvas(this.width, this.height);
|
||||||
|
|
||||||
|
if (!Number.isNaN(delay) && delay <= 1) {
|
||||||
|
delay = 10;
|
||||||
|
}
|
||||||
|
|
||||||
const frame = {
|
const frame = {
|
||||||
actualOffset: this.totalDuration,
|
actualOffset: this.totalDuration,
|
||||||
delay: delay || Math.max(Math.round(actualDelay / 10), 2),
|
delay: delay || Math.max(Math.round(actualDelay / 10), 2),
|
||||||
|
@ -246,7 +253,7 @@ class CanvasEx {
|
||||||
gif.start();
|
gif.start();
|
||||||
for (let i = 0; i < this.frames.length; ++i) {
|
for (let i = 0; i < this.frames.length; ++i) {
|
||||||
const frame = this.frames[i];
|
const frame = this.frames[i];
|
||||||
gif.setDelay(frame.delay);
|
gif.setDelay(frame.actualDelay);
|
||||||
gif.addFrame(frame.ctx);
|
gif.addFrame(frame.ctx);
|
||||||
}
|
}
|
||||||
gif.finish();
|
gif.finish();
|
||||||
|
|
Reference in a new issue