WangYuLue / image-conversion

A simple and easy-to-use JS image convert tools, which can specify size to compress the image.
https://demo.wangyulue.com/image-conversion/
MIT License
903 stars 139 forks source link

GIF compression outputs static GIF #33

Open Distortedlogic opened 3 years ago

Distortedlogic commented 3 years ago

Describe the bug

When gifs are compressed, they become static image of first frame only.

import { compress } from "image-conversion";
const compressed_gif = await compress(YOUR_GIF_FILE_HERE, {
  quality: 0.8,
  type: `image/gif`,
});

view your newly compressed gif

Expected behavior gif should maintain animation after compression when the gif ext type is specified

before stonks

after 1de62654aac4f93cc4588979cdce0de6619cda01e2b79eef73246e1e504b810e

Desktop (please complete the following information):

darkdread commented 3 years ago

It's not a bug, canvas does not support animation. However, it is possible to draw the gif on canvas using this library gifler.

Compressing the gif on the other hand, requires decoding of the gif file and compressing it frame-by-frame. omggif is a decoder/encoder for gif files. So the entire process to compress gif would be to decode the gif file, compress it frame-by-frame, then encode it back and draw it on canvas using gifler.