Skip to content

Instantly share code, notes, and snippets.

@peterpro
Created December 24, 2018 08:52
Show Gist options
  • Select an option

  • Save peterpro/b23d54dae041c5a55eb26dd2a0d85288 to your computer and use it in GitHub Desktop.

Select an option

Save peterpro/b23d54dae041c5a55eb26dd2a0d85288 to your computer and use it in GitHub Desktop.
Papke - 2
function getSnap()
{
// !!! change this to multiply width/height!
// на моём компе 8 даёт 15300 * 5000, но вешает файрфокс
var factor = 5;
var engineCanvas = Human.renderer.canvas.canvas;
var engineRect = engineCanvas.getBoundingClientRect();
var width = engineRect.width;
var height = engineRect.height;
// Get dimensions
var targetWidth = width*5;
var targetHeight = height*5;
// Aspect fix
if (targetWidth >= targetHeight) {
targetHeight = window.Math.floor(height / width * targetWidth);
} else if (targetWidth < targetHeight) {
targetWidth = window.Math.floor(width / height * targetHeight);
}
// Pause timeline if playing
var wasPlaying = false;
if (Human.timeline.playing) {
wasPlaying = true;
Human.timeline.pause();
}
Human.renderer.forceRenderFrame();
// Create output canvas
var outputCanvas = document.createElement('canvas');
var outputContext = outputCanvas.getContext('2d');
outputCanvas.width = targetWidth;
outputCanvas.height = targetHeight;
args = [engineCanvas, 0, 0, targetWidth, targetHeight];
outputContext.drawImage.apply(outputContext, args);
// Post-render cleanup
Human.renderer.forceRenderFrame();
if(wasPlaying) {
Human.timeline.unpause();
}
//outputImage = outputCanvas.toDataURL('image/png').replace("image/png", "image/octet-stream");;
outputImage = Canvas2Image.saveAsPNG(outputCanvas);
//window.location.href = outputImage;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment