Skip to content

Commit

Permalink
fix(img-cropper): fix the file type output
Browse files Browse the repository at this point in the history
  • Loading branch information
Enlcxx committed Dec 3, 2018
1 parent 12ee7fa commit 0ba5290
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export class ResizingCroppingImagesExample03Component {
onCropped(e) {
this.croppedImage = e.dataURL;
console.log(e);
console.log(this.img);
}

constructor(
Expand Down
13 changes: 6 additions & 7 deletions src/lib/resizing-cropping-images/resizing-cropping-images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,14 +287,13 @@ export class LyResizingCroppingImages {

this._fileName = _img.value.replace(/.*(\/|\\)/, '');


/** Set type */
if (!this.config.type) {
this._defaultType = _img.files[0].type;
}
fileReader.addEventListener('loadend', (loadEvent) => {
const originalImageUrl = (loadEvent.target as FileReader).result as string;
this.setImageUrl(originalImageUrl);
/** Set type */
if (!this.config.type) {
this._defaultType = _img.files[0].type;
}
this.cd.markForCheck();
});
fileReader.readAsDataURL(_img.files[0]);
Expand Down Expand Up @@ -601,7 +600,7 @@ export class LyResizingCroppingImages {
const w = img.width * quality;
const h = img.height * quality;
/** Only the new img is shown. */
if (this._defaultType === 'image/png' || fileType === 'image/svg+xml') {
if (fileType === 'image/png' || fileType === 'image/svg+xml') {
octx.globalCompositeOperation = 'copy';
}

Expand Down Expand Up @@ -673,7 +672,7 @@ export class LyResizingCroppingImages {
}
let url;
if (myConfig.type) {
url = result.toDataURL(`image/${myConfig.type}`);
url = result.toDataURL(`${myConfig.type}`);
} else {
url = result.toDataURL(this._defaultType);
}
Expand Down

0 comments on commit 0ba5290

Please sign in to comment.