mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
Fix cropping bug
This commit is contained in:
parent
bb8c5a973b
commit
85b77ca49f
@ -56,13 +56,15 @@ function renderDocument(document, options, windowWidth, windowHeight) {
|
||||
|
||||
function crop(canvas, bounds) {
|
||||
var croppedCanvas = document.createElement("canvas");
|
||||
var left = Math.max(0, bounds.left);
|
||||
var top = Math.max(0, bounds.top);
|
||||
var width = croppedCanvas.width = Math.min(left + canvas.width, Math.max(Math.min(0, bounds.left) + bounds.width, 1));
|
||||
var height = croppedCanvas.height = Math.min(top + canvas.height, Math.max(Math.min(0, bounds.top) + bounds.height, 1));
|
||||
var x1 = Math.min(canvas.width - 1, Math.max(0, bounds.left));
|
||||
var x2 = Math.min(canvas.width, Math.max(1, bounds.left + bounds.width));
|
||||
var y1 = Math.min(canvas.height - 1, Math.max(0, bounds.top));
|
||||
var y2 = Math.min(canvas.height, Math.max(1, bounds.top + bounds.height));
|
||||
var width = croppedCanvas.width = x2 - x1;
|
||||
var height = croppedCanvas.height = y2 - y1;
|
||||
log("Cropping canvas at:", "left:", bounds.left, "top:", bounds.top, "width:", bounds.width, "height:", bounds.height);
|
||||
log("Resulting crop with width", width, "and height", height);
|
||||
croppedCanvas.getContext("2d").drawImage(canvas, left, top, width, height, 0, 0, width, height);
|
||||
log("Resulting crop with width", width, "and height", height, " with x", x1, "and y", y1);
|
||||
croppedCanvas.getContext("2d").drawImage(canvas, x1, y1, width, height, 0, 0, width, height);
|
||||
return croppedCanvas;
|
||||
}
|
||||
|
||||
|
2
build/html2canvas.min.js
vendored
2
build/html2canvas.min.js
vendored
File diff suppressed because one or more lines are too long
14
src/core.js
14
src/core.js
@ -47,13 +47,15 @@ function renderDocument(document, options, windowWidth, windowHeight) {
|
||||
|
||||
function crop(canvas, bounds) {
|
||||
var croppedCanvas = document.createElement("canvas");
|
||||
var left = Math.max(0, bounds.left);
|
||||
var top = Math.max(0, bounds.top);
|
||||
var width = croppedCanvas.width = Math.min(left + canvas.width, Math.max(Math.min(0, bounds.left) + bounds.width, 1));
|
||||
var height = croppedCanvas.height = Math.min(top + canvas.height, Math.max(Math.min(0, bounds.top) + bounds.height, 1));
|
||||
var x1 = Math.min(canvas.width - 1, Math.max(0, bounds.left));
|
||||
var x2 = Math.min(canvas.width, Math.max(1, bounds.left + bounds.width));
|
||||
var y1 = Math.min(canvas.height - 1, Math.max(0, bounds.top));
|
||||
var y2 = Math.min(canvas.height, Math.max(1, bounds.top + bounds.height));
|
||||
var width = croppedCanvas.width = x2 - x1;
|
||||
var height = croppedCanvas.height = y2 - y1;
|
||||
log("Cropping canvas at:", "left:", bounds.left, "top:", bounds.top, "width:", bounds.width, "height:", bounds.height);
|
||||
log("Resulting crop with width", width, "and height", height);
|
||||
croppedCanvas.getContext("2d").drawImage(canvas, left, top, width, height, 0, 0, width, height);
|
||||
log("Resulting crop with width", width, "and height", height, " with x", x1, "and y", y1);
|
||||
croppedCanvas.getContext("2d").drawImage(canvas, x1, y1, width, height, 0, 0, width, height);
|
||||
return croppedCanvas;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user