diff --git a/build/html2canvas.js b/build/html2canvas.js
index 16b0117..7ad1759 100644
--- a/build/html2canvas.js
+++ b/build/html2canvas.js
@@ -8,22 +8,25 @@
 (function(window, document, undefined){
 
 window.html2canvas = function(nodeList, options) {
-    var container = createWindowClone(document, window.innerWidth, window.innerHeight);
-    var clonedWindow = container.contentWindow;
-    var element = (nodeList === undefined) ? document.body : nodeList[0];
-    var node = clonedWindow.document.documentElement;
-    var support = new Support();
-    var imageLoader = new ImageLoader(options, support);
     options = options || {};
     if (options.logging) {
         window.html2canvas.logging = true;
         window.html2canvas.start = Date.now();
     }
+    createWindowClone(document, window.innerWidth, window.innerHeight).then(function(container) {
+        log("Document cloned");
+        var clonedWindow = container.contentWindow;
+        var element = (nodeList === undefined) ? document.body : nodeList[0];
+        var node = clonedWindow.document.documentElement;
+        var support = new Support();
+        var imageLoader = new ImageLoader(options, support);
 
-    var renderer = new CanvasRenderer(documentWidth(), documentHeight(), imageLoader);
-    var parser = new NodeParser(node, renderer, support, imageLoader, options);
 
-    window.console.log(parser);
+        var renderer = new CanvasRenderer(documentWidth(), documentHeight(), imageLoader);
+        var parser = new NodeParser(node, renderer, support, imageLoader, options);
+
+        window.console.log(parser);  
+    });
 };
 
 function documentWidth () {
@@ -50,13 +53,38 @@ function createWindowClone(ownerDocument, width, height) {
     container.style.position = "absolute";
     container.style.width = width + "px";
     container.style.height = height + "px";
-
     ownerDocument.body.appendChild(container);
 
-    var documentClone = container.contentWindow.document;
-    documentClone.replaceChild(documentClone.adoptNode(documentElement), documentClone.documentElement);
+    return new Promise(function(resolve) {
+        var loadedTimer = function() {
+            /* Chrome doesn't detect relative background-images assigned in style sheets when fetched through getComputedStyle,
+            before a certain time has  passed
+             */
+            if (container.contentWindow.getComputedStyle(div, null)['backgroundImage'] !== "none") {
+                documentClone.body.removeChild(div);
+                documentClone.body.removeChild(style);
+                resolve(container);
+            } else {
+                window.setTimeout(loadedTimer, 10);
+            }
+        };
+        var documentClone = container.contentWindow.document;
+        /* Chrome doesn't detect relative background-images assigned in inline <style> sheets when fetched through getComputedStyle
+        if window url is about:blank, we can assign the url to current by writing onto the document
+         */
+        documentClone.open();
+        documentClone.write("");
+        documentClone.close();
 
-    return container;
+        documentClone.replaceChild(documentClone.adoptNode(documentElement), documentClone.documentElement);
+        var div = documentClone.createElement("div");
+        div.className = "html2canvas-ready-test";
+        documentClone.body.appendChild(div);
+        var style = documentClone.createElement("style");
+        style.innerHTML = "body div.html2canvas-ready-test { background-image:url(data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7); }";
+        documentClone.body.appendChild(style);
+        loadedTimer();
+    });
 }
 
 function NodeParser(element, renderer, support, imageLoader, options) {
@@ -219,7 +247,7 @@ NodeParser.prototype.parse = function(stack) {
     .concat(inFlow).concat(stackLevel0).concat(text).concat(positiveZindex).forEach(function(container) {
         this.paint(container);
         if (rendered.indexOf(container.node) !== -1) {
-            window.console.log(container, container.node);
+            log(container, container.node);
             throw new Error("rendering twice");
         }
         rendered.push(container.node);
@@ -578,7 +606,6 @@ function ImageContainer(src, cors) {
     });
 }
 
-
 function ImageLoader(options, support) {
     this.link = null;
     this.options = options;
@@ -875,6 +902,29 @@ function isPercentage(value) {
     return value.toString().indexOf("%") !== -1;
 }
 
+/*
+ Copyright (c) 2013 Yehuda Katz, Tom Dale, and contributors
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
+ this software and associated documentation files (the "Software"), to deal in
+ the Software without restriction, including without limitation the rights to
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+ of the Software, and to permit persons to whom the Software is furnished to do
+ so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in all
+ copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND 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.
+ */
+!function(){var a,b,c,d;!function(){var e={},f={};a=function(a,b,c){e[a]={deps:b,callback:c}},d=c=b=function(a){function c(b){if("."!==b.charAt(0))return b;for(var c=b.split("/"),d=a.split("/").slice(0,-1),e=0,f=c.length;f>e;e++){var g=c[e];if(".."===g)d.pop();else{if("."===g)continue;d.push(g)}}return d.join("/")}if(d._eak_seen=e,f[a])return f[a];if(f[a]={},!e[a])throw new Error("Could not find module "+a);for(var g,h=e[a],i=h.deps,j=h.callback,k=[],l=0,m=i.length;m>l;l++)"exports"===i[l]?k.push(g={}):k.push(b(c(i[l])));var n=j.apply(this,k);return f[a]=g||n}}(),a("promise/all",["./utils","exports"],function(a,b){"use strict";function c(a){var b=this;if(!d(a))throw new TypeError("You must pass an array to all.");return new b(function(b,c){function d(a){return function(b){f(a,b)}}function f(a,c){h[a]=c,0===--i&&b(h)}var g,h=[],i=a.length;0===i&&b([]);for(var j=0;j<a.length;j++)g=a[j],g&&e(g.then)?g.then(d(j),c):f(j,g)})}var d=a.isArray,e=a.isFunction;b.all=c}),a("promise/asap",["exports"],function(a){"use strict";function b(){return function(){process.nextTick(e)}}function c(){var a=0,b=new i(e),c=document.createTextNode("");return b.observe(c,{characterData:!0}),function(){c.data=a=++a%2}}function d(){return function(){j.setTimeout(e,1)}}function e(){for(var a=0;a<k.length;a++){var b=k[a],c=b[0],d=b[1];c(d)}k=[]}function f(a,b){var c=k.push([a,b]);1===c&&g()}var g,h="undefined"!=typeof window?window:{},i=h.MutationObserver||h.WebKitMutationObserver,j="undefined"!=typeof global?global:this,k=[];g="undefined"!=typeof process&&"[object process]"==={}.toString.call(process)?b():i?c():d(),a.asap=f}),a("promise/cast",["exports"],function(a){"use strict";function b(a){if(a&&"object"==typeof a&&a.constructor===this)return a;var b=this;return new b(function(b){b(a)})}a.cast=b}),a("promise/config",["exports"],function(a){"use strict";function b(a,b){return 2!==arguments.length?c[a]:(c[a]=b,void 0)}var c={instrument:!1};a.config=c,a.configure=b}),a("promise/polyfill",["./promise","./utils","exports"],function(a,b,c){"use strict";function d(){var a="Promise"in window&&"cast"in window.Promise&&"resolve"in window.Promise&&"reject"in window.Promise&&"all"in window.Promise&&"race"in window.Promise&&function(){var a;return new window.Promise(function(b){a=b}),f(a)}();a||(window.Promise=e)}var e=a.Promise,f=b.isFunction;c.polyfill=d}),a("promise/promise",["./config","./utils","./cast","./all","./race","./resolve","./reject","./asap","exports"],function(a,b,c,d,e,f,g,h,i){"use strict";function j(a){if(!w(a))throw new TypeError("You must pass a resolver function as the first argument to the promise constructor");if(!(this instanceof j))throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");this._subscribers=[],k(a,this)}function k(a,b){function c(a){p(b,a)}function d(a){r(b,a)}try{a(c,d)}catch(e){d(e)}}function l(a,b,c,d){var e,f,g,h,i=w(c);if(i)try{e=c(d),g=!0}catch(j){h=!0,f=j}else e=d,g=!0;o(b,e)||(i&&g?p(b,e):h?r(b,f):a===F?p(b,e):a===G&&r(b,e))}function m(a,b,c,d){var e=a._subscribers,f=e.length;e[f]=b,e[f+F]=c,e[f+G]=d}function n(a,b){for(var c,d,e=a._subscribers,f=a._detail,g=0;g<e.length;g+=3)c=e[g],d=e[g+b],l(b,c,d,f);a._subscribers=null}function o(a,b){var c,d=null;try{if(a===b)throw new TypeError("A promises callback cannot return that same promise.");if(v(b)&&(d=b.then,w(d)))return d.call(b,function(d){return c?!0:(c=!0,b!==d?p(a,d):q(a,d),void 0)},function(b){return c?!0:(c=!0,r(a,b),void 0)}),!0}catch(e){return c?!0:(r(a,e),!0)}return!1}function p(a,b){a===b?q(a,b):o(a,b)||q(a,b)}function q(a,b){a._state===D&&(a._state=E,a._detail=b,u.async(s,a))}function r(a,b){a._state===D&&(a._state=E,a._detail=b,u.async(t,a))}function s(a){n(a,a._state=F)}function t(a){n(a,a._state=G)}var u=a.config,v=(a.configure,b.objectOrFunction),w=b.isFunction,x=(b.now,c.cast),y=d.all,z=e.race,A=f.resolve,B=g.reject,C=h.asap;u.async=C;var D=void 0,E=0,F=1,G=2;j.prototype={constructor:j,_state:void 0,_detail:void 0,_subscribers:void 0,then:function(a,b){var c=this,d=new this.constructor(function(){});if(this._state){var e=arguments;u.async(function(){l(c._state,d,e[c._state-1],c._detail)})}else m(this,d,a,b);return d},"catch":function(a){return this.then(null,a)}},j.all=y,j.cast=x,j.race=z,j.resolve=A,j.reject=B,i.Promise=j}),a("promise/race",["./utils","exports"],function(a,b){"use strict";function c(a){var b=this;if(!d(a))throw new TypeError("You must pass an array to race.");return new b(function(b,c){for(var d,e=0;e<a.length;e++)d=a[e],d&&"function"==typeof d.then?d.then(b,c):b(d)})}var d=a.isArray;b.race=c}),a("promise/reject",["exports"],function(a){"use strict";function b(a){var b=this;return new b(function(b,c){c(a)})}a.reject=b}),a("promise/resolve",["exports"],function(a){"use strict";function b(a){var b=this;return new b(function(b){b(a)})}a.resolve=b}),a("promise/utils",["exports"],function(a){"use strict";function b(a){return c(a)||"object"==typeof a&&null!==a}function c(a){return"function"==typeof a}function d(a){return"[object Array]"===Object.prototype.toString.call(a)}var e=Date.now||function(){return(new Date).getTime()};a.objectOrFunction=b,a.isFunction=c,a.isArray=d,a.now=e}),b("promise/polyfill").polyfill()}();
+
 function Renderer(width, height, images) {
     this.width = width;
     this.height = height;
@@ -907,15 +957,15 @@ Renderer.prototype.renderBorder = function(data) {
 
 Renderer.prototype.renderBackgroundImage = function(container, bounds) {
     var backgroundImages = container.parseBackgroundImages();
-    backgroundImages.reverse().forEach(function(backgroundImage, index) {
+    backgroundImages.reverse().forEach(function(backgroundImage, index, arr) {
         if (backgroundImage.method === "url") {
             var image = this.images.get(backgroundImage.args[0]);
             if (image) {
-                this.renderBackgroundRepeating(container, bounds, image, index);
+                this.renderBackgroundRepeating(container, bounds, image, arr.length - (index+1));
             } else {
                 log("Error loading background-image", backgroundImage.args[0]);
             }
-        }
+        }  
     }, this);
 };
 
@@ -927,17 +977,17 @@ Renderer.prototype.renderBackgroundRepeating = function(container, bounds, image
     switch (repeat) {
         case "repeat-x":
         case "repeat no-repeat":
-            this.backgroundRepeatShape(imageContainer, position, bounds, bounds.left, bounds.top + position.top, 99999, imageContainer.image.height);
+            this.backgroundRepeatShape(imageContainer, position, size, bounds, bounds.left, bounds.top + position.top, 99999, imageContainer.image.height);
             break;
         case "repeat-y":
         case "no-repeat repeat":
-            this.backgroundRepeatShape(imageContainer, position, bounds, bounds.left + position.left, bounds.top, imageContainer.image.width, 99999);
+            this.backgroundRepeatShape(imageContainer, position, size, bounds, bounds.left + position.left, bounds.top, imageContainer.image.width, 99999);
             break;
         case "no-repeat":
-            this.backgroundRepeatShape(imageContainer, position, bounds, bounds.left + position.left, bounds.top + position.top, imageContainer.image.width, imageContainer.image.height);
+            this.backgroundRepeatShape(imageContainer, position, size, bounds, bounds.left + position.left, bounds.top + position.top, imageContainer.image.width, imageContainer.image.height);
             break;
         default:
-            this.renderBackgroundRepeat(imageContainer, position, {top: bounds.top, left: bounds.left});
+            this.renderBackgroundRepeat(imageContainer, position, size, {top: bounds.top, left: bounds.left});
             break;
     }
 };
@@ -999,27 +1049,40 @@ CanvasRenderer.prototype.text = function(text, left, bottom) {
     this.ctx.fillText(text, left, bottom);
 };
 
-CanvasRenderer.prototype.backgroundRepeatShape = function(imageContainer, backgroundPosition, bounds, left, top, width, height) {
+CanvasRenderer.prototype.backgroundRepeatShape = function(imageContainer, backgroundPosition, size, bounds, left, top, width, height) {
     var shape = [
         ["line", Math.round(left), Math.round(top)],
         ["line", Math.round(left + width), Math.round(top)],
         ["line", Math.round(left + width), Math.round(height + top)],
         ["line", Math.round(left), Math.round(height + top)]
     ];
-    console.log(shape);
     this.clip(shape, function() {
         this.renderBackgroundRepeat(imageContainer, backgroundPosition, bounds);
     }, this);
 };
 
-CanvasRenderer.prototype.renderBackgroundRepeat = function(imageContainer, backgroundPosition, bounds) {
+CanvasRenderer.prototype.renderBackgroundRepeat = function(imageContainer, backgroundPosition, size, bounds) {
     var offsetX = Math.round(bounds.left + backgroundPosition.left), offsetY = Math.round(bounds.top + backgroundPosition.top);
-    this.setFillStyle(this.ctx.createPattern(imageContainer.image, "repeat"));
+    this.setFillStyle(this.ctx.createPattern(this.resizeImage(imageContainer, size), "repeat"));
     this.ctx.translate(offsetX, offsetY);
     this.ctx.fill();
     this.ctx.translate(-offsetX, -offsetY);
 };
 
+CanvasRenderer.prototype.resizeImage = function(imageContainer, size) {
+    var image = imageContainer.image;
+    if(image.width === size.width && image.height === size.height) {
+        return image;
+    }
+
+    var ctx, canvas = document.createElement('canvas');
+    canvas.width = size.width;
+    canvas.height = size.height;
+    ctx = canvas.getContext("2d");
+    ctx.drawImage(image, 0, 0, image.width, image.height, 0, 0, size.width, size.height );
+    return canvas;
+};
+
 function StackingContext(hasOwnStacking, opacity, element, parent) {
     NodeContainer.call(this, element, parent);
     this.ownStacking = hasOwnStacking;
diff --git a/build/html2canvas.min.js b/build/html2canvas.min.js
index 0454c47..d7fdeb1 100644
--- a/build/html2canvas.min.js
+++ b/build/html2canvas.min.js
@@ -4,4 +4,4 @@
 
   Released under MIT License
 */
-(function(t,e,n){function o(){return Math.max(Math.max(e.body.scrollWidth,e.documentElement.scrollWidth),Math.max(e.body.offsetWidth,e.documentElement.offsetWidth),Math.max(e.body.clientWidth,e.documentElement.clientWidth))}function i(){return Math.max(Math.max(e.body.scrollHeight,e.documentElement.scrollHeight),Math.max(e.body.offsetHeight,e.documentElement.offsetHeight),Math.max(e.body.clientHeight,e.documentElement.clientHeight))}function r(t,e,n){var o=t.documentElement.cloneNode(!0),i=t.createElement("iframe");i.style.display="hidden",i.style.position="absolute",i.style.width=e+"px",i.style.height=n+"px",t.body.appendChild(i);var r=i.contentWindow.document;return r.replaceChild(r.adoptNode(o),r.documentElement),i}function s(t,e,n,o,i){this.renderer=e,this.options=i,this.range=null,this.support=n,this.stack=new _(!0,1,t.ownerDocument,null);var r=new P(t,null);r.visibile=r.isElementVisible(),this.nodes=[r].concat(this.getChildren(r)).filter(function(t){return t.visible=t.isElementVisible()}),this.images=o.fetch(this.nodes.filter(C)),this.createStackingContexts(),this.sortStackingContexts(this.stack),this.images.ready.then(N(function(){W("Images loaded, starting parsing"),this.parse(this.stack),i.onrendered(e.canvas)},this))}function a(t){return 0>t.cssInt("zIndex")}function c(t){return t.cssInt("zIndex")>0}function h(t){return 0===t.cssInt("zIndex")}function u(t){return-1!==["inline","inline-block","inline-table"].indexOf(t.css("display"))}function p(t){return t instanceof _}function d(t){return t.node.data.trim().length>0}function l(t){return/^(normal|none|0px)$/.test(t.parent.css("letterSpacing"))}function f(t,e,n,o,i,r,s){e[0]>0||e[1]>0?(t.push(["line",o[0].start.x,o[0].start.y]),o[0].curveTo(t),o[1].curveTo(t)):t.push(["line",r,s]),(n[0]>0||n[1]>0)&&t.push(["line",i[0].start.x,i[0].start.y])}function g(t){return["TopLeft","TopRight","BottomRight","BottomLeft"].map(function(e){var n=t.css("border"+e+"Radius"),o=n.split(" ");return 1>=o.length&&(o[1]=o[0]),o.map(m)})}function m(t){return parseInt(t,10)}function y(t,e,n,o){var i=4*((Math.sqrt(2)-1)/3),r=n*i,s=o*i,a=t+n,c=e+o;return{topLeft:w({x:t,y:c},{x:t,y:c-s},{x:a-r,y:e},{x:a,y:e}),topRight:w({x:t,y:e},{x:t+r,y:e},{x:a,y:c-s},{x:a,y:c}),bottomRight:w({x:a,y:e},{x:a,y:e+s},{x:t+r,y:c},{x:t,y:c}),bottomLeft:w({x:a,y:c},{x:a-r,y:c},{x:t,y:e+s},{x:t,y:e})}}function b(t,e,n){var o=t.left,i=t.top,r=t.width,s=t.height,a=e[0][0],c=e[0][1],h=e[1][0],u=e[1][1],p=e[2][0],d=e[2][1],l=e[3][0],f=e[3][1],g=r-h,m=s-d,b=r-p,w=s-f;return{topLeftOuter:y(o,i,a,c).topLeft.subdivide(.5),topLeftInner:y(o+n[3].width,i+n[0].width,Math.max(0,a-n[3].width),Math.max(0,c-n[0].width)).topLeft.subdivide(.5),topRightOuter:y(o+g,i,h,u).topRight.subdivide(.5),topRightInner:y(o+Math.min(g,r+n[3].width),i+n[0].width,g>r+n[3].width?0:h-n[3].width,u-n[0].width).topRight.subdivide(.5),bottomRightOuter:y(o+b,i+m,p,d).bottomRight.subdivide(.5),bottomRightInner:y(o+Math.min(b,r+n[3].width),i+Math.min(m,s+n[0].width),Math.max(0,p-n[1].width),Math.max(0,d-n[2].width)).bottomRight.subdivide(.5),bottomLeftOuter:y(o,i+w,l,f).bottomLeft.subdivide(.5),bottomLeftInner:y(o+n[3].width,i+w,Math.max(0,l-n[3].width),Math.max(0,f-n[2].width)).bottomLeft.subdivide(.5)}}function w(t,e,n,o){var i=function(t,e,n){return{x:t.x+(e.x-t.x)*n,y:t.y+(e.y-t.y)*n}};return{start:t,startControl:e,endControl:n,end:o,subdivide:function(r){var s=i(t,e,r),a=i(e,n,r),c=i(n,o,r),h=i(s,a,r),u=i(a,c,r),p=i(h,u,r);return[w(t,s,h,p),w(p,u,c,o)]},curveTo:function(t){t.push(["bezierCurve",e.x,e.y,n.x,n.y,o.x,o.y])},curveToReversed:function(o){o.push(["bezierCurve",n.x,n.y,e.x,e.y,t.x,t.y])}}}function x(t,e,n,o,i,r,s){var a=[];return e[0]>0||e[1]>0?(a.push(["line",o[1].start.x,o[1].start.y]),o[1].curveTo(a)):a.push(["line",t.c1[0],t.c1[1]]),n[0]>0||n[1]>0?(a.push(["line",r[0].start.x,r[0].start.y]),r[0].curveTo(a),a.push(["line",s[0].end.x,s[0].end.y]),s[0].curveToReversed(a)):(a.push(["line",t.c2[0],t.c2[1]]),a.push(["line",t.c3[0],t.c3[1]])),e[0]>0||e[1]>0?(a.push(["line",i[1].end.x,i[1].end.y]),i[1].curveToReversed(a)):a.push(["line",t.c4[0],t.c4[1]]),a}function v(t){return t.node.nodeType!==Node.ELEMENT_NODE||-1===["SCRIPT","HEAD","TITLE","OBJECT","BR"].indexOf(t.node.nodeName)}function k(t){return[].concat.apply([],t)}function R(t){return t.nodeType===Node.TEXT_NODE||t.nodeType===Node.ELEMENT_NODE}function I(t){var e=t.css("position"),n="absolute"===e||"relative"===e?t.css("zIndex"):"auto";return"auto"!==n}function B(t){return"static"!==t.css("position")}function E(t){return"none"!==t.css("float")}function T(t){var e=this;return function(){return!t.apply(e,arguments)}}function C(t){return t.node.nodeType===Node.ELEMENT_NODE}function O(t){return t.node.nodeType===Node.TEXT_NODE}function S(t,e){return t.cssInt("zIndex")-e.cssInt("zIndex")}function L(t){return 1>t.css("opacity")}function N(t,e){return function(){return t.apply(e,arguments)}}function M(t,e){this.src=t,this.image=new Image;var n=this.image;this.promise=new Promise(function(o,i){n.onload=o,n.onerror=i,e&&(n.crossOrigin="anonymous"),n.src=t})}function D(e,n){this.link=null,this.options=e,this.support=n,this.origin=t.location.protocol+t.location.host}function W(){t.html2canvas.logging&&t.console&&t.console.log&&t.console.log.apply(t.console,[Date.now()-t.html2canvas.start+"ms","html2canvas:"].concat([].slice.call(arguments,0)))}function P(t,e){this.node=t,this.parent=e,this.stack=null,this.bounds=null,this.visible=null,this.computedStyles=null,this.styles={},this.backgroundImages=null}function z(t){return-1!==(""+t).indexOf("%")}function F(t,e,n){this.width=t,this.height=e,this.images=n}function H(t,n){F.apply(this,arguments),this.canvas=e.createElement("canvas"),this.canvas.width=t,this.canvas.height=n,this.ctx=this.canvas.getContext("2d"),this.ctx.textBaseline="bottom"}function _(t,e,n,o){P.call(this,n,o),this.ownStacking=t,this.contexts=[],this.children=[],this.opacity=(this.parent?this.parent.stack.opacity:1)*e}function V(){this.rangeBounds=this.testRangeBounds(),this.cors=this.testCORS()}function j(t,e){P.call(this,t,e)}function U(t,e,o){return t.length>0?e+o.toUpperCase():n}t.html2canvas=function(a,c){var h=r(e,t.innerWidth,t.innerHeight),u=h.contentWindow;a===n?e.body:a[0];var p=u.document.documentElement,d=new V,l=new D(c,d);c=c||{},c.logging&&(t.html2canvas.logging=!0,t.html2canvas.start=Date.now());var f=new H(o(),i(),l),g=new s(p,f,d,l,c);t.console.log(g)},s.prototype.getChildren=function(t){return k([].filter.call(t.node.childNodes,R).map(function(e){var n=[e.nodeType===Node.TEXT_NODE?new j(e,t):new P(e,t)].filter(v);return e.nodeType===Node.ELEMENT_NODE&&n.length?n[0].isElementVisible()?n.concat(this.getChildren(n[0])):[]:n},this))},s.prototype.newStackingContext=function(t,e){var n=new _(e,t.cssFloat("opacity"),t.node,t.parent);n.visible=t.visible;var o=n.getParentStack(this);o.contexts.push(n),t.stack=n},s.prototype.createStackingContexts=function(){this.nodes.forEach(function(t){C(t)&&(this.isRootElement(t)||L(t)||I(t)||this.isBodyWithTransparentRoot(t))?this.newStackingContext(t,!0):C(t)&&B(t)?this.newStackingContext(t,!1):t.assignStack(t.parent.stack)},this)},s.prototype.isBodyWithTransparentRoot=function(t){return"BODY"===t.node.nodeName&&this.renderer.isTransparent(t.parent.css("backgroundColor"))},s.prototype.isRootElement=function(t){return"HTML"===t.node.nodeName},s.prototype.sortStackingContexts=function(t){t.contexts.sort(S),t.contexts.forEach(this.sortStackingContexts,this)},s.prototype.parseBounds=function(t){return t.bounds=this.getBounds(t.node)},s.prototype.getBounds=function(t){if(t.getBoundingClientRect){var e=t.getBoundingClientRect();return{top:e.top,bottom:e.bottom||e.top+e.height,left:e.left,width:t.offsetWidth,height:t.offsetHeight}}return{}},s.prototype.parseTextBounds=function(t){return function(e,n,o){if("none"!==t.parent.css("textDecoration")||0!==e.trim().length){var i=o.slice(0,n).join("").length;if(this.support.rangeBounds)return this.getRangeBounds(t.node,i,e.length);if(t.node&&"string"==typeof t.node.data){var r=t.node.splitText(e.length),s=this.getWrapperBounds(t.node);return t.node=r,s}}}},s.prototype.getWrapperBounds=function(t){var e=t.ownerDocument.createElement("wrapper"),n=t.parentNode,o=t.cloneNode(!0);e.appendChild(t.cloneNode(!0)),n.replaceChild(e,t);var i=this.getBounds(e);return n.replaceChild(o,e),i},s.prototype.getRangeBounds=function(t,e,n){var o=this.range||(this.range=t.ownerDocument.createRange());return o.setStart(t,e),o.setEnd(t,e+n),o.getBoundingClientRect()},s.prototype.parse=function(e){var n=e.contexts.filter(a),o=e.children.filter(C),i=o.filter(T(E)),r=i.filter(T(B)).filter(T(u)),s=o.filter(T(B)).filter(E),l=i.filter(T(B)).filter(u),f=e.contexts.concat(i.filter(B)).filter(h),g=e.children.filter(O).filter(d),m=e.contexts.filter(c),y=[];n.concat(r).concat(s).concat(l).concat(f).concat(g).concat(m).forEach(function(e){if(this.paint(e),-1!==y.indexOf(e.node))throw t.console.log(e,e.node),Error("rendering twice");y.push(e.node),p(e)&&this.parse(e)},this)},s.prototype.paint=function(t){O(t)?this.paintText(t):this.paintNode(t)},s.prototype.paintNode=function(t){p(t)&&this.renderer.setOpacity(t.opacity);var e=this.parseBounds(t),n=this.parseBorders(t);this.renderer.clip(n.clip,function(){this.renderer.renderBackground(t,e)},this),this.renderer.renderBorders(n.borders)},s.prototype.paintText=function(t){t.applyTextTransform();var e=t.node.data.split(!this.options.letterRendering||l(t)?/(\b| )/:""),n=t.parent.fontWeight(),o=t.parent.css("fontSize"),i=t.parent.css("fontFamily");this.renderer.font(t.parent.css("color"),t.parent.css("fontStyle"),t.parent.css("fontVariant"),n,o,i),e.map(this.parseTextBounds(t),this).forEach(function(t,n){t&&this.renderer.text(e[n],t.left,t.bottom)},this)},s.prototype.parseBorders=function(t){var e=t.bounds,n=g(t),o=["Top","Right","Bottom","Left"].map(function(e){return{width:t.cssInt("border"+e+"Width"),color:t.css("border"+e+"Color"),args:null}}),i=b(e,n,o);return{clip:this.parseBackgroundClip(t,i,o,n,e),borders:o.map(function(t,r){if(t.width>0){var s=e.left,a=e.top,c=e.width,h=e.height-o[2].width;switch(r){case 0:h=o[0].width,t.args=x({c1:[s,a],c2:[s+c,a],c3:[s+c-o[1].width,a+h],c4:[s+o[3].width,a+h]},n[0],n[1],i.topLeftOuter,i.topLeftInner,i.topRightOuter,i.topRightInner);break;case 1:s=e.left+e.width-o[1].width,c=o[1].width,t.args=x({c1:[s+c,a],c2:[s+c,a+h+o[2].width],c3:[s,a+h],c4:[s,a+o[0].width]},n[1],n[2],i.topRightOuter,i.topRightInner,i.bottomRightOuter,i.bottomRightInner);break;case 2:a=a+e.height-o[2].width,h=o[2].width,t.args=x({c1:[s+c,a+h],c2:[s,a+h],c3:[s+o[3].width,a],c4:[s+c-o[3].width,a]},n[2],n[3],i.bottomRightOuter,i.bottomRightInner,i.bottomLeftOuter,i.bottomLeftInner);break;case 3:c=o[3].width,t.args=x({c1:[s,a+h+o[2].width],c2:[s,a],c3:[s+c,a+o[0].width],c4:[s+c,a+h]},n[3],n[0],i.bottomLeftOuter,i.bottomLeftInner,i.topLeftOuter,i.topLeftInner)}}return t})}},s.prototype.parseBackgroundClip=function(t,e,n,o,i){var r=t.css("backgroundClip"),s=[];switch(r){case"content-box":case"padding-box":f(s,o[0],o[1],e.topLeftInner,e.topRightInner,i.left+n[3].width,i.top+n[0].width),f(s,o[1],o[2],e.topRightInner,e.bottomRightInner,i.left+i.width-n[1].width,i.top+n[0].width),f(s,o[2],o[3],e.bottomRightInner,e.bottomLeftInner,i.left+i.width-n[1].width,i.top+i.height-n[2].width),f(s,o[3],o[0],e.bottomLeftInner,e.topLeftInner,i.left+n[3].width,i.top+i.height-n[2].width);break;default:f(s,o[0],o[1],e.topLeftOuter,e.topRightOuter,i.left,i.top),f(s,o[1],o[2],e.topRightOuter,e.bottomRightOuter,i.left+i.width,i.top),f(s,o[2],o[3],e.bottomRightOuter,e.bottomLeftOuter,i.left+i.width,i.top+i.height),f(s,o[3],o[0],e.bottomLeftOuter,e.topLeftOuter,i.left,i.top+i.height)}return s},D.prototype.findImages=function(t,e){var n=e.parseBackgroundImages(),o=n.filter(this.isImageBackground).map(this.getBackgroundUrl).filter(this.imageExists(t)).map(this.loadImage,this);return t.concat(o)},D.prototype.getBackgroundUrl=function(t){return t.args[0]},D.prototype.isImageBackground=function(t){return"url"===t.method},D.prototype.loadImage=function(t){return t.match(/data:image\/.*;base64,/i)?new M(t.replace(/url\(['"]{0,}|['"]{0,}\)$/gi,""),!1):this.isSameOrigin(t)||this.options.allowTaint===!0?new M(t,!1):this.support.cors&&!this.options.allowTaint&&this.options.useCORS?new M(t,!0):this.options.proxy?new ProxyImageContainer(t):new DummyImageContainer(t)},D.prototype.imageExists=function(t){return function(e){return!t.some(function(t){return t.src!==e.src})}},D.prototype.isSameOrigin=function(t){var n=this.link||(this.link=e.createElement("a"));n.href=t,n.href=n.href;var o=n.protocol+n.host;return o===this.origin},D.prototype.getPromise=function(t){return t.promise},D.prototype.get=function(t){var e=null;return this.images.some(function(n){return(e=n).src===t})?e:null},D.prototype.fetch=function(t){return this.images=t.reduce(N(this.findImages,this),[]),this.ready=Promise.all(this.images.map(this.getPromise)),this},P.prototype.assignStack=function(t){this.stack=t,t.children.push(this)},P.prototype.isElementVisible=function(){return this.node.nodeType===Node.TEXT_NODE?this.parent.visible:"none"!==this.css("display")&&"hidden"!==this.css("visibility")&&!this.node.hasAttribute("data-html2canvas-ignore")},P.prototype.css=function(t){return this.computedStyles||(this.computedStyles=this.node.ownerDocument.defaultView.getComputedStyle(this.node,null)),this.styles[t]||(this.styles[t]=this.computedStyles[t])},P.prototype.cssInt=function(t){var e=parseInt(this.css(t),10);return Number.isNaN(e)?0:e},P.prototype.cssFloat=function(t){var e=parseFloat(this.css(t));return Number.isNaN(e)?0:e},P.prototype.fontWeight=function(){var t=this.css("fontWeight");switch(parseInt(t,10)){case 401:t="bold";break;case 400:t="normal"}return t},P.prototype.parseBackgroundImages=function(){var t,e,o,i,r,s,a,c=" \r\n	",h=[],u=0,p=0,d=function(){t&&('"'===e.substr(0,1)&&(e=e.substr(1,e.length-2)),e&&a.push(e),"-"===t.substr(0,1)&&(i=t.indexOf("-",1)+1)>0&&(o=t.substr(0,i),t=t.substr(i)),h.push({prefix:o,method:t.toLowerCase(),value:r,args:a,image:null})),a=[],t=o=e=r=""};return a=[],t=o=e=r="",this.css("backgroundImage").split("").forEach(function(o){if(!(0===u&&c.indexOf(o)>-1)){switch(o){case'"':s?s===o&&(s=null):s=o;break;case"(":if(s)break;if(0===u)return u=1,r+=o,n;p++;break;case")":if(s)break;if(1===u){if(0===p)return u=0,r+=o,d(),n;p--}break;case",":if(s)break;if(0===u)return d(),n;if(1===u&&0===p&&!t.match(/^url$/i))return a.push(e),e="",r+=o,n}r+=o,0===u?t+=o:e+=o}}),d(),this.backgroundImages||(this.backgroundImages=h)},P.prototype.cssList=function(t,e){var n=(this.css(t)||"").split(",");return n=n[e||0]||n[0]||"auto",n=n.trim().split(" "),1===n.length&&(n=[n[0],n[0]]),n},P.prototype.parseBackgroundSize=function(t,e,n){var o,i,r=this.cssList("backgroundSize",n);if(z(r[0]))o=t.width*parseFloat(r[0])/100;else{if(/contain|cover/.test(r[0])){var s=t.width/t.height,a=e.width/e.height;return a>s^"contain"===r[0]?{width:t.height*a,height:t.height}:{width:t.width,height:t.width/a}}o=parseInt(r[0],10)}return i="auto"===r[0]&&"auto"===r[1]?e.height:"auto"===r[1]?o/e.width*e.height:z(r[1])?t.height*parseFloat(r[1])/100:parseInt(r[1],10),"auto"===r[0]&&(o=i/e.height*e.width),{width:o,height:i}},P.prototype.parseBackgroundPosition=function(t,e,n,o){var i,r,s=this.cssList("backgroundPosition",n);return i=z(s[0])?(t.width-(o||e).width)*(parseFloat(s[0])/100):parseInt(s[0],10),r="auto"===s[1]?i/e.width*e.height:z(s[1])?(t.height-(o||e).height)*parseFloat(s[1])/100:parseInt(s[1],10),"auto"===s[0]&&(i=r/e.height*e.width),{left:i,top:r}},P.prototype.parseBackgroundRepeat=function(t){return this.cssList("backgroundRepeat",t)[0]},F.prototype.renderBackground=function(t,e){e.height>0&&e.width>0&&(this.renderBackgroundColor(t,e),this.renderBackgroundImage(t,e))},F.prototype.renderBackgroundColor=function(t,e){var n=t.css("backgroundColor");this.isTransparent(n)||this.rectangle(e.left,e.top,e.width,e.height,t.css("backgroundColor"))},F.prototype.renderBorders=function(t){t.forEach(this.renderBorder,this)},F.prototype.renderBorder=function(t){this.isTransparent(t.color)||null===t.args||this.drawShape(t.args,t.color)},F.prototype.renderBackgroundImage=function(t,e){var n=t.parseBackgroundImages();n.reverse().forEach(function(n,o){if("url"===n.method){var i=this.images.get(n.args[0]);i?this.renderBackgroundRepeating(t,e,i,o):W("Error loading background-image",n.args[0])}},this)},F.prototype.renderBackgroundRepeating=function(t,e,n,o){var i=t.parseBackgroundSize(e,n.image,o),r=t.parseBackgroundPosition(e,n.image,o,i),s=t.parseBackgroundRepeat(o);switch(s){case"repeat-x":case"repeat no-repeat":this.backgroundRepeatShape(n,r,e,e.left,e.top+r.top,99999,n.image.height);break;case"repeat-y":case"no-repeat repeat":this.backgroundRepeatShape(n,r,e,e.left+r.left,e.top,n.image.width,99999);break;case"no-repeat":this.backgroundRepeatShape(n,r,e,e.left+r.left,e.top+r.top,n.image.width,n.image.height);break;default:this.renderBackgroundRepeat(n,r,{top:e.top,left:e.left})}},F.prototype.isTransparent=function(t){return!t||"transparent"===t||"rgba(0, 0, 0, 0)"===t},H.prototype=Object.create(F.prototype),H.prototype.setFillStyle=function(t){return this.ctx.fillStyle=t,this.ctx},H.prototype.rectangle=function(t,e,n,o,i){this.setFillStyle(i).fillRect(t,e,n,o)},H.prototype.drawShape=function(t,e){this.shape(t),this.setFillStyle(e).fill()},H.prototype.clip=function(t,e,n){this.ctx.save(),this.shape(t).clip(),e.call(n),this.ctx.restore()},H.prototype.shape=function(t){return this.ctx.beginPath(),t.forEach(function(t,e){this.ctx[0===e?"moveTo":t[0]+"To"].apply(this.ctx,t.slice(1))},this),this.ctx.closePath(),this.ctx},H.prototype.font=function(t,e,n,o,i,r){this.setFillStyle(t).font=[e,n,o,i,r].join(" ")},H.prototype.setOpacity=function(t){this.ctx.globalAlpha=t},H.prototype.text=function(t,e,n){this.ctx.fillText(t,e,n)},H.prototype.backgroundRepeatShape=function(t,e,n,o,i,r,s){var a=[["line",Math.round(o),Math.round(i)],["line",Math.round(o+r),Math.round(i)],["line",Math.round(o+r),Math.round(s+i)],["line",Math.round(o),Math.round(s+i)]];console.log(a),this.clip(a,function(){this.renderBackgroundRepeat(t,e,n)},this)},H.prototype.renderBackgroundRepeat=function(t,e,n){var o=Math.round(n.left+e.left),i=Math.round(n.top+e.top);this.setFillStyle(this.ctx.createPattern(t.image,"repeat")),this.ctx.translate(o,i),this.ctx.fill(),this.ctx.translate(-o,-i)},_.prototype=Object.create(P.prototype),_.prototype.getParentStack=function(t){var e=this.parent?this.parent.stack:null;return e?e.ownStacking?e:e.getParentStack(t):t.stack},V.prototype.testRangeBounds=function(){var t,n,o,i,r=!1;return e.createRange&&(t=e.createRange(),t.getBoundingClientRect&&(n=e.createElement("boundtest"),n.style.height="123px",n.style.display="block",e.body.appendChild(n),t.selectNode(n),o=t.getBoundingClientRect(),i=o.height,123===i&&(r=!0),e.body.removeChild(n))),r},V.prototype.testCORS=function(){return(new Image).crossOrigin!==n},j.prototype=Object.create(P.prototype),j.prototype.applyTextTransform=function(){this.node.data=this.transform(this.parent.css("textTransform"))},j.prototype.transform=function(t){var e=this.node.data;switch(t){case"lowercase":return e.toLowerCase();case"capitalize":return e.replace(/(^|\s|:|-|\(|\))([a-z])/g,U);case"uppercase":return e.toUpperCase();default:return e}}})(window,document);
\ No newline at end of file
+(function(t,e,n){function r(){return Math.max(Math.max(e.body.scrollWidth,e.documentElement.scrollWidth),Math.max(e.body.offsetWidth,e.documentElement.offsetWidth),Math.max(e.body.clientWidth,e.documentElement.clientWidth))}function o(){return Math.max(Math.max(e.body.scrollHeight,e.documentElement.scrollHeight),Math.max(e.body.offsetHeight,e.documentElement.offsetHeight),Math.max(e.body.clientHeight,e.documentElement.clientHeight))}function i(e,n,r){var o=e.documentElement.cloneNode(!0),i=e.createElement("iframe");return i.style.display="hidden",i.style.position="absolute",i.style.width=n+"px",i.style.height=r+"px",e.body.appendChild(i),new Promise(function(e){var n=function(){"none"!==i.contentWindow.getComputedStyle(s,null).backgroundImage?(r.body.removeChild(s),r.body.removeChild(a),e(i)):t.setTimeout(n,10)},r=i.contentWindow.document;r.open(),r.write(""),r.close(),r.replaceChild(r.adoptNode(o),r.documentElement);var s=r.createElement("div");s.className="html2canvas-ready-test",r.body.appendChild(s);var a=r.createElement("style");a.innerHTML="body div.html2canvas-ready-test { background-image:url(data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7); }",r.body.appendChild(a),n()})}function s(t,e,n,r,o){this.renderer=e,this.options=o,this.range=null,this.support=n,this.stack=new W(!0,1,t.ownerDocument,null);var i=new P(t,null);i.visibile=i.isElementVisible(),this.nodes=[i].concat(this.getChildren(i)).filter(function(t){return t.visible=t.isElementVisible()}),this.images=r.fetch(this.nodes.filter(C)),this.createStackingContexts(),this.sortStackingContexts(this.stack),this.images.ready.then(N(function(){_("Images loaded, starting parsing"),this.parse(this.stack),o.onrendered(e.canvas)},this))}function a(t){return 0>t.cssInt("zIndex")}function c(t){return t.cssInt("zIndex")>0}function u(t){return 0===t.cssInt("zIndex")}function h(t){return-1!==["inline","inline-block","inline-table"].indexOf(t.css("display"))}function p(t){return t instanceof W}function l(t){return t.node.data.trim().length>0}function d(t){return/^(normal|none|0px)$/.test(t.parent.css("letterSpacing"))}function f(t,e,n,r,o,i,s){e[0]>0||e[1]>0?(t.push(["line",r[0].start.x,r[0].start.y]),r[0].curveTo(t),r[1].curveTo(t)):t.push(["line",i,s]),(n[0]>0||n[1]>0)&&t.push(["line",o[0].start.x,o[0].start.y])}function g(t){return["TopLeft","TopRight","BottomRight","BottomLeft"].map(function(e){var n=t.css("border"+e+"Radius"),r=n.split(" ");return 1>=r.length&&(r[1]=r[0]),r.map(m)})}function m(t){return parseInt(t,10)}function y(t,e,n,r){var o=4*((Math.sqrt(2)-1)/3),i=n*o,s=r*o,a=t+n,c=e+r;return{topLeft:v({x:t,y:c},{x:t,y:c-s},{x:a-i,y:e},{x:a,y:e}),topRight:v({x:t,y:e},{x:t+i,y:e},{x:a,y:c-s},{x:a,y:c}),bottomRight:v({x:a,y:e},{x:a,y:e+s},{x:t+i,y:c},{x:t,y:c}),bottomLeft:v({x:a,y:c},{x:a-i,y:c},{x:t,y:e+s},{x:t,y:e})}}function b(t,e,n){var r=t.left,o=t.top,i=t.width,s=t.height,a=e[0][0],c=e[0][1],u=e[1][0],h=e[1][1],p=e[2][0],l=e[2][1],d=e[3][0],f=e[3][1],g=i-u,m=s-l,b=i-p,v=s-f;return{topLeftOuter:y(r,o,a,c).topLeft.subdivide(.5),topLeftInner:y(r+n[3].width,o+n[0].width,Math.max(0,a-n[3].width),Math.max(0,c-n[0].width)).topLeft.subdivide(.5),topRightOuter:y(r+g,o,u,h).topRight.subdivide(.5),topRightInner:y(r+Math.min(g,i+n[3].width),o+n[0].width,g>i+n[3].width?0:u-n[3].width,h-n[0].width).topRight.subdivide(.5),bottomRightOuter:y(r+b,o+m,p,l).bottomRight.subdivide(.5),bottomRightInner:y(r+Math.min(b,i+n[3].width),o+Math.min(m,s+n[0].width),Math.max(0,p-n[1].width),Math.max(0,l-n[2].width)).bottomRight.subdivide(.5),bottomLeftOuter:y(r,o+v,d,f).bottomLeft.subdivide(.5),bottomLeftInner:y(r+n[3].width,o+v,Math.max(0,d-n[3].width),Math.max(0,f-n[2].width)).bottomLeft.subdivide(.5)}}function v(t,e,n,r){var o=function(t,e,n){return{x:t.x+(e.x-t.x)*n,y:t.y+(e.y-t.y)*n}};return{start:t,startControl:e,endControl:n,end:r,subdivide:function(i){var s=o(t,e,i),a=o(e,n,i),c=o(n,r,i),u=o(s,a,i),h=o(a,c,i),p=o(u,h,i);return[v(t,s,u,p),v(p,h,c,r)]},curveTo:function(t){t.push(["bezierCurve",e.x,e.y,n.x,n.y,r.x,r.y])},curveToReversed:function(r){r.push(["bezierCurve",n.x,n.y,e.x,e.y,t.x,t.y])}}}function w(t,e,n,r,o,i,s){var a=[];return e[0]>0||e[1]>0?(a.push(["line",r[1].start.x,r[1].start.y]),r[1].curveTo(a)):a.push(["line",t.c1[0],t.c1[1]]),n[0]>0||n[1]>0?(a.push(["line",i[0].start.x,i[0].start.y]),i[0].curveTo(a),a.push(["line",s[0].end.x,s[0].end.y]),s[0].curveToReversed(a)):(a.push(["line",t.c2[0],t.c2[1]]),a.push(["line",t.c3[0],t.c3[1]])),e[0]>0||e[1]>0?(a.push(["line",o[1].end.x,o[1].end.y]),o[1].curveToReversed(a)):a.push(["line",t.c4[0],t.c4[1]]),a}function x(t){return t.node.nodeType!==Node.ELEMENT_NODE||-1===["SCRIPT","HEAD","TITLE","OBJECT","BR"].indexOf(t.node.nodeName)}function k(t){return[].concat.apply([],t)}function E(t){return t.nodeType===Node.TEXT_NODE||t.nodeType===Node.ELEMENT_NODE}function R(t){var e=t.css("position"),n="absolute"===e||"relative"===e?t.css("zIndex"):"auto";return"auto"!==n}function I(t){return"static"!==t.css("position")}function T(t){return"none"!==t.css("float")}function B(t){var e=this;return function(){return!t.apply(e,arguments)}}function C(t){return t.node.nodeType===Node.ELEMENT_NODE}function O(t){return t.node.nodeType===Node.TEXT_NODE}function S(t,e){return t.cssInt("zIndex")-e.cssInt("zIndex")}function L(t){return 1>t.css("opacity")}function N(t,e){return function(){return t.apply(e,arguments)}}function A(t,e){this.src=t,this.image=new Image;var n=this.image;this.promise=new Promise(function(r,o){n.onload=r,n.onerror=o,e&&(n.crossOrigin="anonymous"),n.src=t})}function M(e,n){this.link=null,this.options=e,this.support=n,this.origin=t.location.protocol+t.location.host}function _(){t.html2canvas.logging&&t.console&&t.console.log&&t.console.log.apply(t.console,[Date.now()-t.html2canvas.start+"ms","html2canvas:"].concat([].slice.call(arguments,0)))}function P(t,e){this.node=t,this.parent=e,this.stack=null,this.bounds=null,this.visible=null,this.computedStyles=null,this.styles={},this.backgroundImages=null}function D(t){return-1!==(""+t).indexOf("%")}function j(t,e,n){this.width=t,this.height=e,this.images=n}function F(t,n){j.apply(this,arguments),this.canvas=e.createElement("canvas"),this.canvas.width=t,this.canvas.height=n,this.ctx=this.canvas.getContext("2d"),this.ctx.textBaseline="bottom"}function W(t,e,n,r){P.call(this,n,r),this.ownStacking=t,this.contexts=[],this.children=[],this.opacity=(this.parent?this.parent.stack.opacity:1)*e}function z(){this.rangeBounds=this.testRangeBounds(),this.cors=this.testCORS()}function H(t,e){P.call(this,t,e)}function V(t,e,r){return t.length>0?e+r.toUpperCase():n}t.html2canvas=function(a,c){c=c||{},c.logging&&(t.html2canvas.logging=!0,t.html2canvas.start=Date.now()),i(e,t.innerWidth,t.innerHeight).then(function(i){_("Document cloned");var u=i.contentWindow;a===n?e.body:a[0];var h=u.document.documentElement,p=new z,l=new M(c,p),d=new F(r(),o(),l),f=new s(h,d,p,l,c);t.console.log(f)})},s.prototype.getChildren=function(t){return k([].filter.call(t.node.childNodes,E).map(function(e){var n=[e.nodeType===Node.TEXT_NODE?new H(e,t):new P(e,t)].filter(x);return e.nodeType===Node.ELEMENT_NODE&&n.length?n[0].isElementVisible()?n.concat(this.getChildren(n[0])):[]:n},this))},s.prototype.newStackingContext=function(t,e){var n=new W(e,t.cssFloat("opacity"),t.node,t.parent);n.visible=t.visible;var r=n.getParentStack(this);r.contexts.push(n),t.stack=n},s.prototype.createStackingContexts=function(){this.nodes.forEach(function(t){C(t)&&(this.isRootElement(t)||L(t)||R(t)||this.isBodyWithTransparentRoot(t))?this.newStackingContext(t,!0):C(t)&&I(t)?this.newStackingContext(t,!1):t.assignStack(t.parent.stack)},this)},s.prototype.isBodyWithTransparentRoot=function(t){return"BODY"===t.node.nodeName&&this.renderer.isTransparent(t.parent.css("backgroundColor"))},s.prototype.isRootElement=function(t){return"HTML"===t.node.nodeName},s.prototype.sortStackingContexts=function(t){t.contexts.sort(S),t.contexts.forEach(this.sortStackingContexts,this)},s.prototype.parseBounds=function(t){return t.bounds=this.getBounds(t.node)},s.prototype.getBounds=function(t){if(t.getBoundingClientRect){var e=t.getBoundingClientRect();return{top:e.top,bottom:e.bottom||e.top+e.height,left:e.left,width:t.offsetWidth,height:t.offsetHeight}}return{}},s.prototype.parseTextBounds=function(t){return function(e,n,r){if("none"!==t.parent.css("textDecoration")||0!==e.trim().length){var o=r.slice(0,n).join("").length;if(this.support.rangeBounds)return this.getRangeBounds(t.node,o,e.length);if(t.node&&"string"==typeof t.node.data){var i=t.node.splitText(e.length),s=this.getWrapperBounds(t.node);return t.node=i,s}}}},s.prototype.getWrapperBounds=function(t){var e=t.ownerDocument.createElement("wrapper"),n=t.parentNode,r=t.cloneNode(!0);e.appendChild(t.cloneNode(!0)),n.replaceChild(e,t);var o=this.getBounds(e);return n.replaceChild(r,e),o},s.prototype.getRangeBounds=function(t,e,n){var r=this.range||(this.range=t.ownerDocument.createRange());return r.setStart(t,e),r.setEnd(t,e+n),r.getBoundingClientRect()},s.prototype.parse=function(t){var e=t.contexts.filter(a),n=t.children.filter(C),r=n.filter(B(T)),o=r.filter(B(I)).filter(B(h)),i=n.filter(B(I)).filter(T),s=r.filter(B(I)).filter(h),d=t.contexts.concat(r.filter(I)).filter(u),f=t.children.filter(O).filter(l),g=t.contexts.filter(c),m=[];e.concat(o).concat(i).concat(s).concat(d).concat(f).concat(g).forEach(function(t){if(this.paint(t),-1!==m.indexOf(t.node))throw _(t,t.node),Error("rendering twice");m.push(t.node),p(t)&&this.parse(t)},this)},s.prototype.paint=function(t){O(t)?this.paintText(t):this.paintNode(t)},s.prototype.paintNode=function(t){p(t)&&this.renderer.setOpacity(t.opacity);var e=this.parseBounds(t),n=this.parseBorders(t);this.renderer.clip(n.clip,function(){this.renderer.renderBackground(t,e)},this),this.renderer.renderBorders(n.borders)},s.prototype.paintText=function(t){t.applyTextTransform();var e=t.node.data.split(!this.options.letterRendering||d(t)?/(\b| )/:""),n=t.parent.fontWeight(),r=t.parent.css("fontSize"),o=t.parent.css("fontFamily");this.renderer.font(t.parent.css("color"),t.parent.css("fontStyle"),t.parent.css("fontVariant"),n,r,o),e.map(this.parseTextBounds(t),this).forEach(function(t,n){t&&this.renderer.text(e[n],t.left,t.bottom)},this)},s.prototype.parseBorders=function(t){var e=t.bounds,n=g(t),r=["Top","Right","Bottom","Left"].map(function(e){return{width:t.cssInt("border"+e+"Width"),color:t.css("border"+e+"Color"),args:null}}),o=b(e,n,r);return{clip:this.parseBackgroundClip(t,o,r,n,e),borders:r.map(function(t,i){if(t.width>0){var s=e.left,a=e.top,c=e.width,u=e.height-r[2].width;switch(i){case 0:u=r[0].width,t.args=w({c1:[s,a],c2:[s+c,a],c3:[s+c-r[1].width,a+u],c4:[s+r[3].width,a+u]},n[0],n[1],o.topLeftOuter,o.topLeftInner,o.topRightOuter,o.topRightInner);break;case 1:s=e.left+e.width-r[1].width,c=r[1].width,t.args=w({c1:[s+c,a],c2:[s+c,a+u+r[2].width],c3:[s,a+u],c4:[s,a+r[0].width]},n[1],n[2],o.topRightOuter,o.topRightInner,o.bottomRightOuter,o.bottomRightInner);break;case 2:a=a+e.height-r[2].width,u=r[2].width,t.args=w({c1:[s+c,a+u],c2:[s,a+u],c3:[s+r[3].width,a],c4:[s+c-r[3].width,a]},n[2],n[3],o.bottomRightOuter,o.bottomRightInner,o.bottomLeftOuter,o.bottomLeftInner);break;case 3:c=r[3].width,t.args=w({c1:[s,a+u+r[2].width],c2:[s,a],c3:[s+c,a+r[0].width],c4:[s+c,a+u]},n[3],n[0],o.bottomLeftOuter,o.bottomLeftInner,o.topLeftOuter,o.topLeftInner)}}return t})}},s.prototype.parseBackgroundClip=function(t,e,n,r,o){var i=t.css("backgroundClip"),s=[];switch(i){case"content-box":case"padding-box":f(s,r[0],r[1],e.topLeftInner,e.topRightInner,o.left+n[3].width,o.top+n[0].width),f(s,r[1],r[2],e.topRightInner,e.bottomRightInner,o.left+o.width-n[1].width,o.top+n[0].width),f(s,r[2],r[3],e.bottomRightInner,e.bottomLeftInner,o.left+o.width-n[1].width,o.top+o.height-n[2].width),f(s,r[3],r[0],e.bottomLeftInner,e.topLeftInner,o.left+n[3].width,o.top+o.height-n[2].width);break;default:f(s,r[0],r[1],e.topLeftOuter,e.topRightOuter,o.left,o.top),f(s,r[1],r[2],e.topRightOuter,e.bottomRightOuter,o.left+o.width,o.top),f(s,r[2],r[3],e.bottomRightOuter,e.bottomLeftOuter,o.left+o.width,o.top+o.height),f(s,r[3],r[0],e.bottomLeftOuter,e.topLeftOuter,o.left,o.top+o.height)}return s},M.prototype.findImages=function(t,e){var n=e.parseBackgroundImages(),r=n.filter(this.isImageBackground).map(this.getBackgroundUrl).filter(this.imageExists(t)).map(this.loadImage,this);return t.concat(r)},M.prototype.getBackgroundUrl=function(t){return t.args[0]},M.prototype.isImageBackground=function(t){return"url"===t.method},M.prototype.loadImage=function(t){return t.match(/data:image\/.*;base64,/i)?new A(t.replace(/url\(['"]{0,}|['"]{0,}\)$/gi,""),!1):this.isSameOrigin(t)||this.options.allowTaint===!0?new A(t,!1):this.support.cors&&!this.options.allowTaint&&this.options.useCORS?new A(t,!0):this.options.proxy?new ProxyImageContainer(t):new DummyImageContainer(t)},M.prototype.imageExists=function(t){return function(e){return!t.some(function(t){return t.src!==e.src})}},M.prototype.isSameOrigin=function(t){var n=this.link||(this.link=e.createElement("a"));n.href=t,n.href=n.href;var r=n.protocol+n.host;return r===this.origin},M.prototype.getPromise=function(t){return t.promise},M.prototype.get=function(t){var e=null;return this.images.some(function(n){return(e=n).src===t})?e:null},M.prototype.fetch=function(t){return this.images=t.reduce(N(this.findImages,this),[]),this.ready=Promise.all(this.images.map(this.getPromise)),this},P.prototype.assignStack=function(t){this.stack=t,t.children.push(this)},P.prototype.isElementVisible=function(){return this.node.nodeType===Node.TEXT_NODE?this.parent.visible:"none"!==this.css("display")&&"hidden"!==this.css("visibility")&&!this.node.hasAttribute("data-html2canvas-ignore")},P.prototype.css=function(t){return this.computedStyles||(this.computedStyles=this.node.ownerDocument.defaultView.getComputedStyle(this.node,null)),this.styles[t]||(this.styles[t]=this.computedStyles[t])},P.prototype.cssInt=function(t){var e=parseInt(this.css(t),10);return Number.isNaN(e)?0:e},P.prototype.cssFloat=function(t){var e=parseFloat(this.css(t));return Number.isNaN(e)?0:e},P.prototype.fontWeight=function(){var t=this.css("fontWeight");switch(parseInt(t,10)){case 401:t="bold";break;case 400:t="normal"}return t},P.prototype.parseBackgroundImages=function(){var t,e,r,o,i,s,a,c=" \r\n	",u=[],h=0,p=0,l=function(){t&&('"'===e.substr(0,1)&&(e=e.substr(1,e.length-2)),e&&a.push(e),"-"===t.substr(0,1)&&(o=t.indexOf("-",1)+1)>0&&(r=t.substr(0,o),t=t.substr(o)),u.push({prefix:r,method:t.toLowerCase(),value:i,args:a,image:null})),a=[],t=r=e=i=""};return a=[],t=r=e=i="",this.css("backgroundImage").split("").forEach(function(r){if(!(0===h&&c.indexOf(r)>-1)){switch(r){case'"':s?s===r&&(s=null):s=r;break;case"(":if(s)break;if(0===h)return h=1,i+=r,n;p++;break;case")":if(s)break;if(1===h){if(0===p)return h=0,i+=r,l(),n;p--}break;case",":if(s)break;if(0===h)return l(),n;if(1===h&&0===p&&!t.match(/^url$/i))return a.push(e),e="",i+=r,n}i+=r,0===h?t+=r:e+=r}}),l(),this.backgroundImages||(this.backgroundImages=u)},P.prototype.cssList=function(t,e){var n=(this.css(t)||"").split(",");return n=n[e||0]||n[0]||"auto",n=n.trim().split(" "),1===n.length&&(n=[n[0],n[0]]),n},P.prototype.parseBackgroundSize=function(t,e,n){var r,o,i=this.cssList("backgroundSize",n);if(D(i[0]))r=t.width*parseFloat(i[0])/100;else{if(/contain|cover/.test(i[0])){var s=t.width/t.height,a=e.width/e.height;return a>s^"contain"===i[0]?{width:t.height*a,height:t.height}:{width:t.width,height:t.width/a}}r=parseInt(i[0],10)}return o="auto"===i[0]&&"auto"===i[1]?e.height:"auto"===i[1]?r/e.width*e.height:D(i[1])?t.height*parseFloat(i[1])/100:parseInt(i[1],10),"auto"===i[0]&&(r=o/e.height*e.width),{width:r,height:o}},P.prototype.parseBackgroundPosition=function(t,e,n,r){var o,i,s=this.cssList("backgroundPosition",n);return o=D(s[0])?(t.width-(r||e).width)*(parseFloat(s[0])/100):parseInt(s[0],10),i="auto"===s[1]?o/e.width*e.height:D(s[1])?(t.height-(r||e).height)*parseFloat(s[1])/100:parseInt(s[1],10),"auto"===s[0]&&(o=i/e.height*e.width),{left:o,top:i}},P.prototype.parseBackgroundRepeat=function(t){return this.cssList("backgroundRepeat",t)[0]},!function(){var r,o,i,s;!function(){var t={},e={};r=function(e,n,r){t[e]={deps:n,callback:r}},s=i=o=function(n){function r(t){if("."!==t.charAt(0))return t;for(var e=t.split("/"),r=n.split("/").slice(0,-1),o=0,i=e.length;i>o;o++){var s=e[o];if(".."===s)r.pop();else{if("."===s)continue;r.push(s)}}return r.join("/")}if(s._eak_seen=t,e[n])return e[n];if(e[n]={},!t[n])throw Error("Could not find module "+n);for(var i,a=t[n],c=a.deps,u=a.callback,h=[],p=0,l=c.length;l>p;p++)"exports"===c[p]?h.push(i={}):h.push(o(r(c[p])));var d=u.apply(this,h);return e[n]=i||d}}(),r("promise/all",["./utils","exports"],function(t,e){"use strict";function n(t){var e=this;if(!r(t))throw new TypeError("You must pass an array to all.");return new e(function(e,n){function r(t){return function(e){i(t,e)}}function i(t,n){a[t]=n,0===--c&&e(a)}var s,a=[],c=t.length;0===c&&e([]);for(var u=0;t.length>u;u++)s=t[u],s&&o(s.then)?s.then(r(u),n):i(u,s)})}var r=t.isArray,o=t.isFunction;e.all=n}),r("promise/asap",["exports"],function(r){"use strict";function o(){return function(){process.nextTick(a)}}function i(){var t=0,n=new p(a),r=e.createTextNode("");return n.observe(r,{characterData:!0}),function(){r.data=t=++t%2}}function s(){return function(){l.setTimeout(a,1)}}function a(){for(var t=0;d.length>t;t++){var e=d[t],n=e[0],r=e[1];n(r)}d=[]}function c(t,e){var n=d.push([t,e]);1===n&&u()}var u,h=t!==n?t:{},p=h.MutationObserver||h.WebKitMutationObserver,l="undefined"!=typeof global?global:this,d=[];u="undefined"!=typeof process&&"[object process]"==={}.toString.call(process)?o():p?i():s(),r.asap=c}),r("promise/cast",["exports"],function(t){"use strict";function e(t){if(t&&"object"==typeof t&&t.constructor===this)return t;var e=this;return new e(function(e){e(t)})}t.cast=e}),r("promise/config",["exports"],function(t){"use strict";function e(t,e){return 2!==arguments.length?n[t]:(n[t]=e,void 0)}var n={instrument:!1};t.config=n,t.configure=e}),r("promise/polyfill",["./promise","./utils","exports"],function(e,n,r){"use strict";function o(){var e="Promise"in t&&"cast"in t.Promise&&"resolve"in t.Promise&&"reject"in t.Promise&&"all"in t.Promise&&"race"in t.Promise&&function(){var e;return new t.Promise(function(t){e=t}),s(e)}();e||(t.Promise=i)}var i=e.Promise,s=n.isFunction;r.polyfill=o}),r("promise/promise",["./config","./utils","./cast","./all","./race","./resolve","./reject","./asap","exports"],function(t,e,n,r,o,i,s,a,c){"use strict";function u(t){if(!k(t))throw new TypeError("You must pass a resolver function as the first argument to the promise constructor");if(!(this instanceof u))throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");this._subscribers=[],h(t,this)}function h(t,e){function n(t){g(e,t)}function r(t){y(e,t)}try{t(n,r)}catch(o){r(o)}}function p(t,e,n,r){var o,i,s,a,c=k(n);if(c)try{o=n(r),s=!0}catch(u){a=!0,i=u}else o=r,s=!0;f(e,o)||(c&&s?g(e,o):a?y(e,i):t===L?g(e,o):t===N&&y(e,o))}function l(t,e,n,r){var o=t._subscribers,i=o.length;o[i]=e,o[i+L]=n,o[i+N]=r}function d(t,e){for(var n,r,o=t._subscribers,i=t._detail,s=0;o.length>s;s+=3)n=o[s],r=o[s+e],p(e,n,r,i);t._subscribers=null}function f(t,e){var n,r=null;try{if(t===e)throw new TypeError("A promises callback cannot return that same promise.");if(x(e)&&(r=e.then,k(r)))return r.call(e,function(r){return n?!0:(n=!0,e!==r?g(t,r):m(t,r),void 0)},function(e){return n?!0:(n=!0,y(t,e),void 0)}),!0}catch(o){return n?!0:(y(t,o),!0)}return!1}function g(t,e){t===e?m(t,e):f(t,e)||m(t,e)}function m(t,e){t._state===O&&(t._state=S,t._detail=e,w.async(b,t))}function y(t,e){t._state===O&&(t._state=S,t._detail=e,w.async(v,t))}function b(t){d(t,t._state=L)}function v(t){d(t,t._state=N)}var w=t.config,x=(t.configure,e.objectOrFunction),k=e.isFunction,E=(e.now,n.cast),R=r.all,I=o.race,T=i.resolve,B=s.reject,C=a.asap;w.async=C;var O=void 0,S=0,L=1,N=2;u.prototype={constructor:u,_state:void 0,_detail:void 0,_subscribers:void 0,then:function(t,e){var n=this,r=new this.constructor(function(){});if(this._state){var o=arguments;w.async(function(){p(n._state,r,o[n._state-1],n._detail)})}else l(this,r,t,e);return r},"catch":function(t){return this.then(null,t)}},u.all=R,u.cast=E,u.race=I,u.resolve=T,u.reject=B,c.Promise=u}),r("promise/race",["./utils","exports"],function(t,e){"use strict";function n(t){var e=this;if(!r(t))throw new TypeError("You must pass an array to race.");return new e(function(e,n){for(var r,o=0;t.length>o;o++)r=t[o],r&&"function"==typeof r.then?r.then(e,n):e(r)})}var r=t.isArray;e.race=n}),r("promise/reject",["exports"],function(t){"use strict";function e(t){var e=this;return new e(function(e,n){n(t)})}t.reject=e}),r("promise/resolve",["exports"],function(t){"use strict";function e(t){var e=this;return new e(function(e){e(t)})}t.resolve=e}),r("promise/utils",["exports"],function(t){"use strict";function e(t){return n(t)||"object"==typeof t&&null!==t}function n(t){return"function"==typeof t}function r(t){return"[object Array]"===Object.prototype.toString.call(t)}var o=Date.now||function(){return(new Date).getTime()};t.objectOrFunction=e,t.isFunction=n,t.isArray=r,t.now=o}),o("promise/polyfill").polyfill()}(),j.prototype.renderBackground=function(t,e){e.height>0&&e.width>0&&(this.renderBackgroundColor(t,e),this.renderBackgroundImage(t,e))},j.prototype.renderBackgroundColor=function(t,e){var n=t.css("backgroundColor");this.isTransparent(n)||this.rectangle(e.left,e.top,e.width,e.height,t.css("backgroundColor"))},j.prototype.renderBorders=function(t){t.forEach(this.renderBorder,this)},j.prototype.renderBorder=function(t){this.isTransparent(t.color)||null===t.args||this.drawShape(t.args,t.color)},j.prototype.renderBackgroundImage=function(t,e){var n=t.parseBackgroundImages();n.reverse().forEach(function(n,r,o){if("url"===n.method){var i=this.images.get(n.args[0]);i?this.renderBackgroundRepeating(t,e,i,o.length-(r+1)):_("Error loading background-image",n.args[0])}},this)},j.prototype.renderBackgroundRepeating=function(t,e,n,r){var o=t.parseBackgroundSize(e,n.image,r),i=t.parseBackgroundPosition(e,n.image,r,o),s=t.parseBackgroundRepeat(r);switch(s){case"repeat-x":case"repeat no-repeat":this.backgroundRepeatShape(n,i,o,e,e.left,e.top+i.top,99999,n.image.height);break;case"repeat-y":case"no-repeat repeat":this.backgroundRepeatShape(n,i,o,e,e.left+i.left,e.top,n.image.width,99999);break;case"no-repeat":this.backgroundRepeatShape(n,i,o,e,e.left+i.left,e.top+i.top,n.image.width,n.image.height);break;default:this.renderBackgroundRepeat(n,i,o,{top:e.top,left:e.left})}},j.prototype.isTransparent=function(t){return!t||"transparent"===t||"rgba(0, 0, 0, 0)"===t},F.prototype=Object.create(j.prototype),F.prototype.setFillStyle=function(t){return this.ctx.fillStyle=t,this.ctx},F.prototype.rectangle=function(t,e,n,r,o){this.setFillStyle(o).fillRect(t,e,n,r)},F.prototype.drawShape=function(t,e){this.shape(t),this.setFillStyle(e).fill()},F.prototype.clip=function(t,e,n){this.ctx.save(),this.shape(t).clip(),e.call(n),this.ctx.restore()},F.prototype.shape=function(t){return this.ctx.beginPath(),t.forEach(function(t,e){this.ctx[0===e?"moveTo":t[0]+"To"].apply(this.ctx,t.slice(1))},this),this.ctx.closePath(),this.ctx},F.prototype.font=function(t,e,n,r,o,i){this.setFillStyle(t).font=[e,n,r,o,i].join(" ")},F.prototype.setOpacity=function(t){this.ctx.globalAlpha=t},F.prototype.text=function(t,e,n){this.ctx.fillText(t,e,n)},F.prototype.backgroundRepeatShape=function(t,e,n,r,o,i,s,a){var c=[["line",Math.round(o),Math.round(i)],["line",Math.round(o+s),Math.round(i)],["line",Math.round(o+s),Math.round(a+i)],["line",Math.round(o),Math.round(a+i)]];this.clip(c,function(){this.renderBackgroundRepeat(t,e,r)},this)},F.prototype.renderBackgroundRepeat=function(t,e,n,r){var o=Math.round(r.left+e.left),i=Math.round(r.top+e.top);this.setFillStyle(this.ctx.createPattern(this.resizeImage(t,n),"repeat")),this.ctx.translate(o,i),this.ctx.fill(),this.ctx.translate(-o,-i)},F.prototype.resizeImage=function(t,n){var r=t.image;if(r.width===n.width&&r.height===n.height)return r;var o,i=e.createElement("canvas");return i.width=n.width,i.height=n.height,o=i.getContext("2d"),o.drawImage(r,0,0,r.width,r.height,0,0,n.width,n.height),i},W.prototype=Object.create(P.prototype),W.prototype.getParentStack=function(t){var e=this.parent?this.parent.stack:null;return e?e.ownStacking?e:e.getParentStack(t):t.stack},z.prototype.testRangeBounds=function(){var t,n,r,o,i=!1;return e.createRange&&(t=e.createRange(),t.getBoundingClientRect&&(n=e.createElement("boundtest"),n.style.height="123px",n.style.display="block",e.body.appendChild(n),t.selectNode(n),r=t.getBoundingClientRect(),o=r.height,123===o&&(i=!0),e.body.removeChild(n))),i},z.prototype.testCORS=function(){return(new Image).crossOrigin!==n},H.prototype=Object.create(P.prototype),H.prototype.applyTextTransform=function(){this.node.data=this.transform(this.parent.css("textTransform"))},H.prototype.transform=function(t){var e=this.node.data;switch(t){case"lowercase":return e.toLowerCase();case"capitalize":return e.replace(/(^|\s|:|-|\(|\))([a-z])/g,V);case"uppercase":return e.toUpperCase();default:return e}}})(window,document);
\ No newline at end of file
diff --git a/src/imagecontainer.js b/src/imagecontainer.js
index 1b77c6d..d0a1fca 100644
--- a/src/imagecontainer.js
+++ b/src/imagecontainer.js
@@ -11,4 +11,3 @@ function ImageContainer(src, cors) {
         image.src = src;
     });
 }
-
diff --git a/src/renderer.js b/src/renderer.js
index 4dbab4e..cc5d1a0 100644
--- a/src/renderer.js
+++ b/src/renderer.js
@@ -30,11 +30,11 @@ Renderer.prototype.renderBorder = function(data) {
 
 Renderer.prototype.renderBackgroundImage = function(container, bounds) {
     var backgroundImages = container.parseBackgroundImages();
-    backgroundImages.reverse().forEach(function(backgroundImage, index) {
+    backgroundImages.reverse().forEach(function(backgroundImage, index, arr) {
         if (backgroundImage.method === "url") {
             var image = this.images.get(backgroundImage.args[0]);
             if (image) {
-                this.renderBackgroundRepeating(container, bounds, image, index);
+                this.renderBackgroundRepeating(container, bounds, image, arr.length - (index+1));
             } else {
                 log("Error loading background-image", backgroundImage.args[0]);
             }
@@ -50,17 +50,17 @@ Renderer.prototype.renderBackgroundRepeating = function(container, bounds, image
     switch (repeat) {
         case "repeat-x":
         case "repeat no-repeat":
-            this.backgroundRepeatShape(imageContainer, position, bounds, bounds.left, bounds.top + position.top, 99999, imageContainer.image.height);
+            this.backgroundRepeatShape(imageContainer, position, size, bounds, bounds.left, bounds.top + position.top, 99999, imageContainer.image.height);
             break;
         case "repeat-y":
         case "no-repeat repeat":
-            this.backgroundRepeatShape(imageContainer, position, bounds, bounds.left + position.left, bounds.top, imageContainer.image.width, 99999);
+            this.backgroundRepeatShape(imageContainer, position, size, bounds, bounds.left + position.left, bounds.top, imageContainer.image.width, 99999);
             break;
         case "no-repeat":
-            this.backgroundRepeatShape(imageContainer, position, bounds, bounds.left + position.left, bounds.top + position.top, imageContainer.image.width, imageContainer.image.height);
+            this.backgroundRepeatShape(imageContainer, position, size, bounds, bounds.left + position.left, bounds.top + position.top, imageContainer.image.width, imageContainer.image.height);
             break;
         default:
-            this.renderBackgroundRepeat(imageContainer, position, {top: bounds.top, left: bounds.left});
+            this.renderBackgroundRepeat(imageContainer, position, size, {top: bounds.top, left: bounds.left});
             break;
     }
 };
diff --git a/src/renderers/canvas.js b/src/renderers/canvas.js
index b71c793..6da13e3 100644
--- a/src/renderers/canvas.js
+++ b/src/renderers/canvas.js
@@ -51,23 +51,36 @@ CanvasRenderer.prototype.text = function(text, left, bottom) {
     this.ctx.fillText(text, left, bottom);
 };
 
-CanvasRenderer.prototype.backgroundRepeatShape = function(imageContainer, backgroundPosition, bounds, left, top, width, height) {
+CanvasRenderer.prototype.backgroundRepeatShape = function(imageContainer, backgroundPosition, size, bounds, left, top, width, height) {
     var shape = [
         ["line", Math.round(left), Math.round(top)],
         ["line", Math.round(left + width), Math.round(top)],
         ["line", Math.round(left + width), Math.round(height + top)],
         ["line", Math.round(left), Math.round(height + top)]
     ];
-    console.log(shape);
     this.clip(shape, function() {
         this.renderBackgroundRepeat(imageContainer, backgroundPosition, bounds);
     }, this);
 };
 
-CanvasRenderer.prototype.renderBackgroundRepeat = function(imageContainer, backgroundPosition, bounds) {
+CanvasRenderer.prototype.renderBackgroundRepeat = function(imageContainer, backgroundPosition, size, bounds) {
     var offsetX = Math.round(bounds.left + backgroundPosition.left), offsetY = Math.round(bounds.top + backgroundPosition.top);
-    this.setFillStyle(this.ctx.createPattern(imageContainer.image, "repeat"));
+    this.setFillStyle(this.ctx.createPattern(this.resizeImage(imageContainer, size), "repeat"));
     this.ctx.translate(offsetX, offsetY);
     this.ctx.fill();
     this.ctx.translate(-offsetX, -offsetY);
 };
+
+CanvasRenderer.prototype.resizeImage = function(imageContainer, size) {
+    var image = imageContainer.image;
+    if(image.width === size.width && image.height === size.height) {
+        return image;
+    }
+
+    var ctx, canvas = document.createElement('canvas');
+    canvas.width = size.width;
+    canvas.height = size.height;
+    ctx = canvas.getContext("2d");
+    ctx.drawImage(image, 0, 0, image.width, image.height, 0, 0, size.width, size.height );
+    return canvas;
+};
diff --git a/tests/test.js b/tests/test.js
index 55da29f..35943dc 100644
--- a/tests/test.js
+++ b/tests/test.js
@@ -11,7 +11,7 @@ var h2cSelector, h2cOptions;
 
     document.write(srcStart + '/tests/assets/jquery-1.6.2.js' + scrEnd);
     document.write(srcStart + '/tests/assets/jquery.plugin.html2canvas.js' + scrEnd);
-    var html2canvas = ['log', 'nodecontainer', 'stackingcontext', 'textcontainer', 'support', 'imagecontainer', 'imageloader', 'core', 'renderer', 'renderers/canvas'], i;
+    var html2canvas = ['log', 'nodecontainer', 'stackingcontext', 'textcontainer', 'support', 'imagecontainer', 'imageloader', 'core', 'renderer', 'promise', 'renderers/canvas'], i;
     for (i = 0; i < html2canvas.length; ++i) {
         document.write(srcStart + '/src/' + html2canvas[i] + '.js?' + Math.random() + scrEnd);
     }