Created
January 3, 2024 06:31
-
-
Save lichspace/145533df062e4a7574c8f10d15e11124 to your computer and use it in GitHub Desktop.
extract pixijs sprite to buffer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Application, Assets, loadNodeFont, utils, Text } from '@pixi/node'; | |
| import { writeFileSync } from 'fs'; | |
| import { Canvas, createImageData, createCanvas } from 'canvas'; | |
| const data = this.app.renderer.extract.pixels(this.app.stage); | |
| const { width, height } = this.app.stage; | |
| const canvas = createCanvas(width, height); | |
| const ctx = canvas.getContext('2d'); | |
| const imagedata = createImageData(new Uint8ClampedArray(data), width, height); | |
| ctx.putImageData(imagedata, 0, 0); | |
| return canvas.toBuffer('image/png'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment