Skip to content

Commit

Permalink
fix: broken text-generation example
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed Dec 11, 2020
1 parent 00cf5fc commit 364f6de
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 185 deletions.
13 changes: 4 additions & 9 deletions examples/text-generation.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,13 @@ font.load(() => {
try {
await PImage.encodePNGToStream(img, writableStreamBuffer)

// For some reason, adding an overlayWith command forces the final image to have
// an alpha channel, even if we call .flatten().
// To work around this, we have to overlay the image, render it as a PNG,
// then put that PNG back into Sharp, flatten it, and render raw.
// Seems like a bug in Sharp that we should make a test case for and report.
const pngBuffer = await sharp(path.resolve(__dirname, 'fixtures/github_logo.png'))
.resize(streamDeck.ICON_SIZE, streamDeck.ICON_SIZE)
.overlayWith(writableStreamBuffer.getContents())
.png()
.composite([{ input: writableStreamBuffer.getContents() }])
.flatten()
.raw()
.toBuffer()
const finalBuffer = await sharp(pngBuffer).flatten().raw().toBuffer()
await streamDeck.fillImage(keyIndex, finalBuffer)
await streamDeck.fillImage(keyIndex, pngBuffer, { format: 'rgba' })
} catch (error) {
console.error(error)
}
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@
"@types/node-hid": "^1.3.0",
"@types/sharp": "^0.26.1",
"codecov": "^3.8.1",
"coveralls": "^3.0.3",
"jest": "^26.6.3",
"jest-haste-map": "^26.6.2",
"jest-resolve": "^26.6.2",
Expand Down

0 comments on commit 364f6de

Please sign in to comment.