Skip to content

Commit

Permalink
feat: support browser usage (jpeg-js#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickhulce committed Apr 21, 2020
1 parent 5737c99 commit 8489174
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 7 additions & 1 deletion lib/decoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,13 @@ var JpegImage = (function jpegImage() {

return constructor;
})();
module.exports = decode;

if (typeof module !== 'undefined') {
module.exports = decode;
} else if (typeof window !== 'undefined') {
window['jpeg-js'] = window['jpeg-js'] || {};
window['jpeg-js'].decode = decode;
}

function decode(jpegData, opts) {
var defaultOpts = {
Expand Down
8 changes: 6 additions & 2 deletions lib/encoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ function JPEGEncoder(quality) {

writeWord(0xFFD9); //EOI

//return new Uint8Array(byteout);
if (typeof module === 'undefined') return new Uint8Array(byteout);
return new Buffer(byteout);

var jpegDataUri = 'data:image/jpeg;base64,' + btoa(byteout.join(''));
Expand Down Expand Up @@ -740,8 +740,12 @@ function JPEGEncoder(quality) {
init();

};
if (typeof module !== undefined) {

if (typeof module !== 'undefined') {
module.exports = encode;
} else if (typeof window !== 'undefined') {
window['jpeg-js'] = window['jpeg-js'] || {};
window['jpeg-js'].encode = encode;
}

function encode(imgData, qu) {
Expand Down

0 comments on commit 8489174

Please sign in to comment.