Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix blurry images #373

Closed
wants to merge 9 commits into from
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2012 Niklas von Hertzen
Copyright (c) 2014 Niklas von Hertzen

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
Expand All @@ -19,4 +19,4 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
OTHER DEALINGS IN THE SOFTWARE.
32 changes: 22 additions & 10 deletions build/html2canvas.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
html2canvas 0.4.1 <http://html2canvas.hertzen.com>
Copyright (c) 2013 Niklas von Hertzen
Copyright (c) 2014 Niklas von Hertzen

Released under MIT License
*/
Expand Down Expand Up @@ -1527,7 +1527,6 @@ _html2canvas.Parse = function (images, options, cb) {
}

function renderImage(ctx, element, image, bounds, borders) {

var paddingLeft = getCSSInt(element, 'paddingLeft'),
paddingTop = getCSSInt(element, 'paddingTop'),
paddingRight = getCSSInt(element, 'paddingRight'),
Expand All @@ -1540,10 +1539,10 @@ _html2canvas.Parse = function (images, options, cb) {
0, //sy
image.width, //sw
image.height, //sh
bounds.left + paddingLeft + borders[3].width, //dx
bounds.top + paddingTop + borders[0].width, // dy
bounds.width - (borders[1].width + borders[3].width + paddingLeft + paddingRight), //dw
bounds.height - (borders[0].width + borders[2].width + paddingTop + paddingBottom) //dh
Math.round(bounds.left + paddingLeft + borders[3].width), //dx
Math.round(bounds.top + paddingTop + borders[0].width), // dy
Math.round(bounds.width - (borders[1].width + borders[3].width + paddingLeft + paddingRight)), //dw
Math.round(bounds.height - (borders[0].width + borders[2].width + paddingTop + paddingBottom)) //dh
);
}

Expand Down Expand Up @@ -1714,9 +1713,19 @@ _html2canvas.Parse = function (images, options, cb) {
brh = borderRadius[2][0],
brv = borderRadius[2][1],
blh = borderRadius[3][0],
blv = borderRadius[3][1],

topWidth = width - trh,
blv = borderRadius[3][1];

var halfHeight = Math.floor(height / 2);
tlh = tlh > halfHeight ? halfHeight : tlh;
tlv = tlv > halfHeight ? halfHeight : tlv;
trh = trh > halfHeight ? halfHeight : trh;
trv = trv > halfHeight ? halfHeight : trv;
brh = brh > halfHeight ? halfHeight : brh;
brv = brv > halfHeight ? halfHeight : brv;
blh = blh > halfHeight ? halfHeight : blh;
blv = blv > halfHeight ? halfHeight : blv;

var topWidth = width - trh,
rightHeight = height - brv,
bottomWidth = width - brh,
leftHeight = height - blv;
Expand Down Expand Up @@ -2993,7 +3002,9 @@ _html2canvas.Renderer.Canvas = function(options) {
newCanvas.height = Math.ceil(bounds.height);
ctx = newCanvas.getContext("2d");

ctx.drawImage(canvas, bounds.left, bounds.top, bounds.width, bounds.height, 0, 0, bounds.width, bounds.height);
var imgData = canvas.getContext("2d").getImageData(bounds.left, bounds.top, bounds.width, bounds.height);
ctx.putImageData(imgData, 0, 0);

canvas = null;
return newCanvas;
}
Expand All @@ -3002,4 +3013,5 @@ _html2canvas.Renderer.Canvas = function(options) {
return canvas;
};
};

})(window,document);
6 changes: 3 additions & 3 deletions build/html2canvas.min.js

Large diffs are not rendered by default.

25 changes: 17 additions & 8 deletions src/Parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,6 @@ _html2canvas.Parse = function (images, options, cb) {
}

function renderImage(ctx, element, image, bounds, borders) {

var paddingLeft = getCSSInt(element, 'paddingLeft'),
paddingTop = getCSSInt(element, 'paddingTop'),
paddingRight = getCSSInt(element, 'paddingRight'),
Expand All @@ -507,10 +506,10 @@ _html2canvas.Parse = function (images, options, cb) {
0, //sy
image.width, //sw
image.height, //sh
bounds.left + paddingLeft + borders[3].width, //dx
bounds.top + paddingTop + borders[0].width, // dy
bounds.width - (borders[1].width + borders[3].width + paddingLeft + paddingRight), //dw
bounds.height - (borders[0].width + borders[2].width + paddingTop + paddingBottom) //dh
Math.round(bounds.left + paddingLeft + borders[3].width), //dx
Math.round(bounds.top + paddingTop + borders[0].width), // dy
Math.round(bounds.width - (borders[1].width + borders[3].width + paddingLeft + paddingRight)), //dw
Math.round(bounds.height - (borders[0].width + borders[2].width + paddingTop + paddingBottom)) //dh
);
}

Expand Down Expand Up @@ -681,9 +680,19 @@ _html2canvas.Parse = function (images, options, cb) {
brh = borderRadius[2][0],
brv = borderRadius[2][1],
blh = borderRadius[3][0],
blv = borderRadius[3][1],

topWidth = width - trh,
blv = borderRadius[3][1];

var halfHeight = Math.floor(height / 2);
tlh = tlh > halfHeight ? halfHeight : tlh;
tlv = tlv > halfHeight ? halfHeight : tlv;
trh = trh > halfHeight ? halfHeight : trh;
trv = trv > halfHeight ? halfHeight : trv;
brh = brh > halfHeight ? halfHeight : brh;
brv = brv > halfHeight ? halfHeight : brv;
blh = blh > halfHeight ? halfHeight : blh;
blv = blv > halfHeight ? halfHeight : blv;

var topWidth = width - trh,
rightHeight = height - brv,
bottomWidth = width - brh,
leftHeight = height - blv;
Expand Down
6 changes: 4 additions & 2 deletions src/renderers/Canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,14 @@ _html2canvas.Renderer.Canvas = function(options) {
newCanvas.height = Math.ceil(bounds.height);
ctx = newCanvas.getContext("2d");

ctx.drawImage(canvas, bounds.left, bounds.top, bounds.width, bounds.height, 0, 0, bounds.width, bounds.height);
var imgData = canvas.getContext("2d").getImageData(bounds.left, bounds.top, bounds.width, bounds.height);
ctx.putImageData(imgData, 0, 0);

canvas = null;
return newCanvas;
}
}

return canvas;
};
};
};