mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
simply resize images to background-size
This commit is contained in:
parent
3edf9fa743
commit
5492d80135
22
src/Parse.js
22
src/Parse.js
@ -779,26 +779,28 @@ _html2canvas.Parse = function (images, options) {
|
|||||||
backgroundPosition = _html2canvas.Util.BackgroundPosition(el, bounds, image, imageIndex, backgroundSize),
|
backgroundPosition = _html2canvas.Util.BackgroundPosition(el, bounds, image, imageIndex, backgroundSize),
|
||||||
backgroundRepeat = getCSS(el, "backgroundRepeat").split(",");
|
backgroundRepeat = getCSS(el, "backgroundRepeat").split(",");
|
||||||
|
|
||||||
|
image = resizeImage(image, backgroundSize);
|
||||||
|
|
||||||
backgroundRepeat = backgroundRepeat[imageIndex] || backgroundRepeat[0];
|
backgroundRepeat = backgroundRepeat[imageIndex] || backgroundRepeat[0];
|
||||||
|
|
||||||
switch (backgroundRepeat) {
|
switch (backgroundRepeat) {
|
||||||
case "repeat-x":
|
case "repeat-x":
|
||||||
backgroundRepeatShape(ctx, image, backgroundPosition, bounds,
|
backgroundRepeatShape(ctx, image, backgroundPosition, bounds,
|
||||||
bounds.left, bounds.top + backgroundPosition.top, 99999, backgroundSize.height);
|
bounds.left, bounds.top + backgroundPosition.top, 99999, image.height);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "repeat-y":
|
case "repeat-y":
|
||||||
backgroundRepeatShape(ctx, image, backgroundPosition, bounds,
|
backgroundRepeatShape(ctx, image, backgroundPosition, bounds,
|
||||||
bounds.left + backgroundPosition.left, bounds.top, backgroundSize.width, 99999);
|
bounds.left + backgroundPosition.left, bounds.top, image.width, 99999);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "no-repeat":
|
case "no-repeat":
|
||||||
backgroundRepeatShape(ctx, image, backgroundPosition, bounds,
|
backgroundRepeatShape(ctx, image, backgroundPosition, bounds,
|
||||||
bounds.left + backgroundPosition.left, bounds.top + backgroundPosition.top, backgroundSize.width, backgroundSize.height);
|
bounds.left + backgroundPosition.left, bounds.top + backgroundPosition.top, image.width, image.height);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
renderBackgroundRepeat(ctx, image, backgroundPosition, { top: bounds.top, left: bounds.left, width: backgroundSize.width, height: backgroundSize.height });
|
renderBackgroundRepeat(ctx, image, backgroundPosition, { top: bounds.top, left: bounds.left, width: image.width, height: image.height });
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -830,6 +832,18 @@ _html2canvas.Parse = function (images, options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function resizeImage(image, bounds) {
|
||||||
|
if(image.width === bounds.width && image.height === bounds.height)
|
||||||
|
return image;
|
||||||
|
|
||||||
|
var ctx, canvas = doc.createElement('canvas');
|
||||||
|
canvas.width = bounds.width;
|
||||||
|
canvas.height = bounds.height;
|
||||||
|
ctx = canvas.getContext("2d");
|
||||||
|
drawImage(ctx, image, 0, 0, image.width, image.height, 0, 0, bounds.width, bounds.height );
|
||||||
|
return canvas;
|
||||||
|
}
|
||||||
|
|
||||||
function setOpacity(ctx, element, parentStack) {
|
function setOpacity(ctx, element, parentStack) {
|
||||||
var opacity = getCSS(element, "opacity") * ((parentStack) ? parentStack.opacity : 1);
|
var opacity = getCSS(element, "opacity") * ((parentStack) ? parentStack.opacity : 1);
|
||||||
ctx.setVariable("globalAlpha", opacity);
|
ctx.setVariable("globalAlpha", opacity);
|
||||||
|
Loading…
Reference in New Issue
Block a user