fix: don't die on missing optional dependency gifencoder
This commit is contained in:
@@ -764,6 +764,7 @@ export async function gif({page, width, height, frames, x = 0, y = 0, repeat = t
|
||||
if (fss.existsSync(path))
|
||||
await fs.unlink(path)
|
||||
//Create encoder
|
||||
try {
|
||||
const GIFEncoder = (await import("gifencoder")).default
|
||||
const encoder = new GIFEncoder(width, height)
|
||||
encoder.createWriteStream().pipe(fss.createWriteStream(path))
|
||||
@@ -784,6 +785,11 @@ export async function gif({page, width, height, frames, x = 0, y = 0, repeat = t
|
||||
const result = await fs.readFile(path, "base64")
|
||||
await fs.unlink(path)
|
||||
return `data:image/gif;base64,${result}`
|
||||
}
|
||||
catch (error) {
|
||||
console.debug(`metrics/puppeteergif > could not create gif: ${error}`)
|
||||
return "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mOcOnfpfwAGfgLYttYINwAAAABJRU5ErkJggg=="
|
||||
}
|
||||
}
|
||||
|
||||
/**D3 node wrapper (loosely based on https://github.com/d3-node/d3-node)*/
|
||||
|
||||
Reference in New Issue
Block a user