Skip to content

Instantly share code, notes, and snippets.

@mkamakura
Created January 30, 2018 09:16
Show Gist options
  • Save mkamakura/6a0b927b28a82d708bae8af00f95b418 to your computer and use it in GitHub Desktop.
Save mkamakura/6a0b927b28a82d708bae8af00f95b418 to your computer and use it in GitHub Desktop.
gif generator
const GifEncoder = require('gifencoder')
const pngFileStream = require('png-file-stream')
const fs = require('fs')
const chalk = require('chalk')
const config = require('./config')
const baseDir = 'e2e/screenshots/'
const dirs = fs.readdirSync(baseDir)
const promises = []
dirs.forEach(async (dir) => {
const pathDir = baseDir + dir
if (!fs.statSync(pathDir).isDirectory()) return
promises.push(generator(pathDir, dir))
})
Promise.race(promises)
function generator(pathDir, dir) {
return new Promise((resolve) => {
const encoder = new GifEncoder(1920, 1080)
console.log(chalk.yellow('start: ', dir))
pngFileStream(pathDir + '/*.png')
.pipe(encoder.createWriteStream(config.gif.encode))
.pipe(fs.createWriteStream(baseDir + dir + '.gif'))
.on('error', (err) => console.log(chalk.red(err)))
.on('finish', () => console.log(chalk.green('finish: ', dir)) || resolve())
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment