fix: don't die on missing optional dependency gifencoder

This commit is contained in:
Simon Lecoq
2023-08-23 22:59:05 -04:00
parent 4f02045e60
commit 54e28d361f

View File

@@ -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)*/