Skip to content

support of dataurl images #267

Merged
merged 2 commits into from May 25, 2014

2 participants

@woolfg
woolfg commented May 25, 2014

support of elements with dataurl src

@diegocr diegocr commented on an outdated diff May 25, 2014
jspdf.plugin.addimage.js
@@ -174,6 +174,9 @@
if(element.nodeName === 'CANVAS') {
var canvas = element;
+ //if already a supported data url image, just return the dataurl
+ } else if (element.getAttribute('src').indexOf('data:image/') === 0) {
@diegocr
Collaborator
diegocr added a note May 25, 2014

I think it should be good checking element.nodeName === 'IMG' before getAttribute()

@diegocr
Collaborator
diegocr added a note May 25, 2014

Also, getAttribute can return null, so using indexOf on it will throw.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@diegocr diegocr and 1 other commented on an outdated diff May 25, 2014
jspdf.plugin.from_html.js
- if (img.complete && img.width + img.height)
- images[url] = images[url] || img;
- if (!--x)
- done();
+ if(img.complete) {
+ //to support data urls in images, set width and height
+ //as those values are not recognized automatically
+ if (img.src.indexOf('data:image/') === 0) {
+ img.width = width || 0;
+ img.height = height || 0;
+ }
+ //if valid image add to known images array
+ if (img.width + img.height) {
+ images[url] = images[url] || img;
+ }
+ if(!--x) {
@diegocr
Collaborator
diegocr added a note May 25, 2014

The call to done() needs to be outside the img.complete block.

@woolfg
woolfg added a note May 25, 2014

you are damn right, sorry, result of a too fast merge conflict resolution ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@diegocr
Collaborator
diegocr commented May 25, 2014

Thanks, i'm merging without testing (since i don't think it's needed)

@diegocr diegocr merged commit c8ea94b into MrRio:master May 25, 2014
@diegocr diegocr added a commit that referenced this pull request May 25, 2014
@diegocr diegocr Minor tweaks related to #267 fac3703
@diegocr
Collaborator
diegocr commented May 25, 2014

I just did a few minor changes on fac3703

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.