diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2c65445..14cc7c4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -7,6 +7,7 @@ jobs: runs-on: ubuntu-latest steps: + - run: sudo apt-get install gifsicle graphicsmagick - uses: actions/checkout@v1 - uses: actions/setup-node@v1 with: diff --git a/packages/gif-creator/__tests__/dev.ts b/packages/gif-creator/__tests__/dev.ts index 05840af..ed1dc71 100644 --- a/packages/gif-creator/__tests__/dev.ts +++ b/packages/gif-creator/__tests__/dev.ts @@ -14,7 +14,7 @@ const drawOptions = { const gameOptions = { maxSnakeLength: 5 }; -const gifOptions = { delay: 100 }; +const gifOptions = { delay: 20 }; const grid = generateGrid(42, 7, { colors: [1, 2, 3, 4], emptyP: 3 }); diff --git a/packages/gif-creator/index.ts b/packages/gif-creator/index.ts index 045de53..9fb4a9d 100644 --- a/packages/gif-creator/index.ts +++ b/packages/gif-creator/index.ts @@ -57,6 +57,7 @@ export const createGif = async ( } const outFileName = path.join(dir, "out.gif"); + const optimizedFileName = path.join(dir, "out.optimized.gif"); await execa( "gm", @@ -74,7 +75,17 @@ export const createGif = async ( ].flat() ); - return fs.readFileSync(outFileName); + await execa( + "gifsicle", + [ + // + "--optimize=3", + outFileName, + ["--output", optimizedFileName], + ].flat() + ); + + return fs.readFileSync(optimizedFileName); } finally { cleanUp(); }