neocotic / qrious

Pure JavaScript library for QR code generation using canvas
https://neocotic.com/qrious
Other
1.55k stars 215 forks source link

Support different image types for toDataURL #16

Closed neocotic closed 10 years ago

neocotic commented 11 years ago

More information: http://stackoverflow.com/questions/14383557/setting-canvas-todataurl-jpg-quality

It would make sense to support both the type (and quality?) parameters instead of only PNG.

Here's a currently workaround until this change is implemented, using JPEG as an example:

var dataUrl = qr.canvas(data).toDataURL('image/jpeg');
richstandbrook commented 11 years ago

This would be good. The work around gives me this error at the moment.

TypeError: 'undefined' is not an object (evaluating 'c.toUpperCase')

http://jsfiddle.net/koorb/U4TXN/4/

neocotic commented 11 years ago

I'm not familiar with the jsPDF library but I think it should work if you change line 39 to the following:

doc.addImage(dataUrl, 'JPEG');
richstandbrook commented 11 years ago

Ah, that was a jsPDF error, sorry. Anyway, can't get it working in jsfiddle but it's fine now in my code. Thanks for the workaround.