Three.js: Exporting to image

Created on 30 Dec 2011  路  8Comments  路  Source: mrdoob/three.js

It'd be great to have a simple way to export a frame of an animation to an image (jpg, png, gif, etc.) for download.

Question

All 8 comments

Yup.

var renderer = new THREE.WebGLRenderer( { preserveDrawingBuffer: true } );
window.open( renderer.domElement.toDataURL( 'image/png' ), 'screenshot' );

It's all you need.

Can you use a similar code for CSS3D to make a screenshot from an embedded iframe? e.g.

var element = document.createElement('iframe');
element.src = 'http://threejs.org/';
element.style.width = '100px';
element.style.height = '100px';

var object = new THREE.CSS3DObject(element);
scene.add(object);

renderer = new THREE.CSS3DRenderer({ preserveDrawingBuffer: true });
window.open( renderer.domElement.toDataURL( 'image/png' ), 'screenshot' );

Nope...

Do you know of any method which let's me take a screenshot from a rendered iframe?

Nope, @nebeleh.

This is done for security reasons. A screen shot would allow a new attack vector in the browser. So that is why browsers don't implement it.
For more information, getScreenshot

How would you adjust the code to take multiple screenshots in a row?

@vgheorghiu please use the forums (https://discourse.threejs.org/) or Stack Overflow for help.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

boyravikumar picture boyravikumar  路  3Comments

zsitro picture zsitro  路  3Comments

danieljack picture danieljack  路  3Comments

ghost picture ghost  路  3Comments

scrubs picture scrubs  路  3Comments