Skip to content

Commit 5c037b6

Browse files
committed
fixed a few image issues related to padding and borders
1 parent 20f6fd9 commit 5c037b6

4 files changed

Lines changed: 40 additions & 17 deletions

File tree

build/html2canvas.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ html2canvas.prototype.init = function(){
8787

8888
// TODO remove jQuery dependency
8989
this.canvas.width = $(document).width();
90-
this.canvas.height = $(document).height()+10;
90+
this.canvas.height = $(document).height();
9191

9292

9393

@@ -486,7 +486,18 @@ html2canvas.prototype.newElement = function(el){
486486
if (el.nodeName=="IMG"){
487487
image = _.loadImage(_.getAttr(el,'src'));
488488
if (image){
489-
this.ctx.drawImage(image,x+parseInt(_.getCSS(el,'padding-left'),10),y+parseInt(_.getCSS(el,'padding-top'),10));
489+
this.ctx.drawImage(
490+
image,
491+
0, //sx
492+
0, //sy
493+
image.width, //sw
494+
image.height, //sh
495+
x+parseInt(_.getCSS(el,'padding-left'),10) + borders[3].width, //dx
496+
y+parseInt(_.getCSS(el,'padding-top'),10) + borders[0].width, // dy
497+
bounds.width - (borders[1].width + borders[3].width + parseInt(_.getCSS(el,'padding-left'),10) + parseInt(_.getCSS(el,'padding-right'),10)), //dw
498+
bounds.height - (borders[0].width + borders[2].width + parseInt(_.getCSS(el,'padding-top'),10) + parseInt(_.getCSS(el,'padding-bottom'),10)) //dh
499+
500+
);
490501
}else{
491502
this.log("Error loading <img>:" + _.getAttr(el,'src'));
492503
}

build/html2canvas.min.js

Lines changed: 14 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Core.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ html2canvas.prototype.init = function(){
5757

5858
// TODO remove jQuery dependency
5959
this.canvas.width = $(document).width();
60-
this.canvas.height = $(document).height()+10;
60+
this.canvas.height = $(document).height();
6161

6262

6363

src/Draw.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,18 @@ html2canvas.prototype.newElement = function(el){
7878
if (el.nodeName=="IMG"){
7979
image = _.loadImage(_.getAttr(el,'src'));
8080
if (image){
81-
this.ctx.drawImage(image,x+parseInt(_.getCSS(el,'padding-left'),10),y+parseInt(_.getCSS(el,'padding-top'),10));
81+
this.ctx.drawImage(
82+
image,
83+
0, //sx
84+
0, //sy
85+
image.width, //sw
86+
image.height, //sh
87+
x+parseInt(_.getCSS(el,'padding-left'),10) + borders[3].width, //dx
88+
y+parseInt(_.getCSS(el,'padding-top'),10) + borders[0].width, // dy
89+
bounds.width - (borders[1].width + borders[3].width + parseInt(_.getCSS(el,'padding-left'),10) + parseInt(_.getCSS(el,'padding-right'),10)), //dw
90+
bounds.height - (borders[0].width + borders[2].width + parseInt(_.getCSS(el,'padding-top'),10) + parseInt(_.getCSS(el,'padding-bottom'),10)) //dh
91+
92+
);
8293
}else{
8394
this.log("Error loading <img>:" + _.getAttr(el,'src'));
8495
}

0 commit comments

Comments
 (0)