Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to save pixijs content as image

Let's say I have a pixijs app like this https://codesandbox.io/s/o3qfi

I need to save the contents rendered by pixijs in the canvas as a screenshot.

I tried accessing the canvas like

app.renderer.view.toDataURL("image/png", 1.0)

and also through

document.getElementsByTagName('canvas')[0].toDataURL("image/png", 1.0)

However both of them returns an empty transparent image, instead of the canvas content rendered by pixijs

like image 921
Ajai Avatar asked Sep 03 '25 09:09

Ajai


1 Answers

You'll need to extract it from the renderer.

For example, if you want to print the stage:

let blob = app.renderer.plugins.extract.image(app.stage).src;
window.location.href = blob.replace("image/png", "image/octet-stream");

Will download the following image:
enter image description here

like image 164
0stone0 Avatar answered Sep 05 '25 01:09

0stone0