Correctly crop content

This commit is contained in:
MoyuScript
2014-03-03 21:19:28 +02:00
parent e2991adc76
commit 57c13e0002
3 changed files with 20 additions and 23 deletions

View File

@ -40,11 +40,19 @@ function renderDocument(document, options, windowWidth, windowHeight) {
if (options.removeContainer) {
container.parentNode.removeChild(container);
}
return renderer.canvas;
return (options.type !== "view" && (node === clonedWindow.document.body || node === clonedWindow.document.documentElement)) ? renderer.canvas : crop(renderer.canvas, bounds);
});
});
}
function crop(canvas, bounds) {
var croppedCanvas = document.createElement("canvas");
croppedCanvas.width = bounds.width;
croppedCanvas.height = bounds.height;
croppedCanvas.getContext("2d").drawImage(canvas, bounds.left, bounds.top, bounds.width, bounds.height, 0, 0, bounds.width, bounds.height);
return croppedCanvas;
}
function documentWidth () {
return Math.max(
Math.max(document.body.scrollWidth, document.documentElement.scrollWidth),