mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
Account for negative bounds in cropping
This commit is contained in:
parent
d2c3378c3e
commit
cfe4137bcc
@ -56,9 +56,11 @@ function renderDocument(document, options, windowWidth, windowHeight) {
|
||||
|
||||
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);
|
||||
var width = croppedCanvas.width = Math.max(Math.min(0, bounds.left) + bounds.width, 1);
|
||||
var height = croppedCanvas.height = Math.max(Math.min(0, bounds.top) + bounds.height, 1);
|
||||
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, Math.max(0, bounds.left), Math.max(0, bounds.top), width, height, 0, 0, width, height);
|
||||
return croppedCanvas;
|
||||
}
|
||||
|
||||
|
4
build/html2canvas.min.js
vendored
4
build/html2canvas.min.js
vendored
File diff suppressed because one or more lines are too long
@ -47,9 +47,11 @@ function renderDocument(document, options, windowWidth, windowHeight) {
|
||||
|
||||
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);
|
||||
var width = croppedCanvas.width = Math.max(Math.min(0, bounds.left) + bounds.width, 1);
|
||||
var height = croppedCanvas.height = Math.max(Math.min(0, bounds.top) + bounds.height, 1);
|
||||
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, Math.max(0, bounds.left), Math.max(0, bounds.top), width, height, 0, 0, width, height);
|
||||
return croppedCanvas;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user