Skip to content

Instantly share code, notes, and snippets.

@lichspace
Created January 3, 2024 06:31
Show Gist options
  • Select an option

  • Save lichspace/145533df062e4a7574c8f10d15e11124 to your computer and use it in GitHub Desktop.

Select an option

Save lichspace/145533df062e4a7574c8f10d15e11124 to your computer and use it in GitHub Desktop.
extract pixijs sprite to buffer
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