Skip to content

Commit e735966

Browse files
committed
tweaks
1 parent 3270cdb commit e735966

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

jspdf.plugin.addimage.js

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@
146146

147147
return imageIndex;
148148
}
149-
, noAliasDefined = function(alias) {
150-
return typeof alias === 'undefined' || alias === null;
149+
, notDefined = function(value) {
150+
return typeof value === 'undefined' || value === null;
151151
}
152152
, generateAliasFromData = function(data) {
153153
// TODO: Alias dynamic generation from imageData's checksum/hash
@@ -448,7 +448,7 @@
448448
compress = compress || false;
449449
format = format.toLowerCase();
450450

451-
if(noAliasDefined(alias))
451+
if(notDefined(alias))
452452
alias = generateAliasFromData(imageData);
453453

454454
if(isDOMElement(imageData))
@@ -488,15 +488,10 @@
488488
var imageIndex = getImageIndex(images),
489489
info = cached_info;
490490

491-
if(!info) {
492-
493-
if(format === 'jpg')
494-
format = 'jpeg';
495-
491+
if(!info)
496492
info = this['process' + format.toUpperCase()](imageData, imageIndex, alias, compress, dataAsBinaryString);
497-
}
498493

499-
if( !info )
494+
if(!info)
500495
throw new Error('An unkwown error occurred whilst processing the image');
501496

502497
writeImageToPDF.call(this, x, y, w, h, info, imageIndex, images);
@@ -553,35 +548,39 @@
553548
};
554549

555550

556-
jsPDFAPI.processJPEG = function(imageData, imageIndex, alias, compress, dataAsBinaryString) {
551+
jsPDFAPI.processJPEG = function(data, index, alias, compress, dataAsBinaryString) {
557552
'use strict'
558553
var colorSpace = this.DEVICE_RGB,
559554
filter = this.DCT_DECODE,
560555
bpc = 8,
561556
dims;
562557

563-
if(this.isString(imageData)) {
564-
dims = getJpegSize(imageData);
565-
return this.createImageInfo(imageData, dims[0], dims[1], colorSpace, bpc, filter, imageIndex, alias);
558+
if(this.isString(data)) {
559+
dims = getJpegSize(data);
560+
return this.createImageInfo(data, dims[0], dims[1], colorSpace, bpc, filter, index, alias);
566561
}
567562

568-
if(this.isArrayBuffer(imageData))
569-
imageData = new Uint8Array(imageData);
563+
if(this.isArrayBuffer(data))
564+
data = new Uint8Array(data);
570565

571-
if(this.isArrayBufferView(imageData)) {
566+
if(this.isArrayBufferView(data)) {
572567

573568
var img = new JpegImage();
574-
img.parse(imageData);
569+
img.parse(data);
575570

576571
/*
577572
* if we already have a stored binary string rep use that
578573
*/
579-
imageData = dataAsBinaryString || this.arrayBufferToBinaryString(imageData);
574+
data = dataAsBinaryString || this.arrayBufferToBinaryString(data);
580575

581-
return this.createImageInfo(imageData, img.width, img.height, colorSpace, bpc, filter, imageIndex, alias);
576+
return this.createImageInfo(data, img.width, img.height, colorSpace, bpc, filter, index, alias);
582577
}
583578

584579
return null;
585580
};
581+
582+
jsPDFAPI.processJPG = function(data, index, alias, compress, dataAsBinaryString) {
583+
return this.processJPEG(data, index, alias, compress, dataAsBinaryString);
584+
}
586585

587586
})(jsPDF.API);

0 commit comments

Comments
 (0)