Skip to content

Commit fac3703

Browse files
committed
Minor tweaks related to #267
1 parent c8ea94b commit fac3703

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

jspdf.plugin.addimage.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,13 @@
172172
}
173173
, createDataURIFromElement = function(element, format) {
174174

175+
//if element is an image which uses data url defintion, just return the dataurl
176+
if (element.nodeName === 'IMG' && element.hasAttribute('src') && (''+element.getAttribute('src')).indexOf('data:image/') === 0) {
177+
return element.getAttribute('src');
178+
}
179+
175180
if(element.nodeName === 'CANVAS') {
176181
var canvas = element;
177-
//if element is an image which uses data url defintion, just return the dataurl
178-
} else if (element.nodeName === 'IMG' && element.getAttribute('src') && element.getAttribute('src').indexOf('data:image/') === 0) {
179-
return element.getAttribute('src');
180182
} else {
181183
var canvas = document.createElement('canvas');
182184
canvas.width = element.clientWidth || element.width;

jspdf.plugin.from_html.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,11 +431,12 @@
431431
//to support data urls in images, set width and height
432432
//as those values are not recognized automatically
433433
if (img.src.indexOf('data:image/') === 0) {
434-
img.width = width || 0;
435-
img.height = height || 0;
434+
img.width = width || img.width || 0;
435+
img.height = height || img.height || 0;
436436
}
437437
//if valid image add to known images array
438438
if (img.width + img.height) {
439+
//TODO: use a hash since data URIs could greatly increase the memory usage
439440
images[url] = images[url] || img;
440441
}
441442
}

0 commit comments

Comments
 (0)