import { Injectable , Inject , forwardRef } from '@angular/core' ; import { Observable , Subject } from 'rxjs' ; import { ImgMaxSizeService } from './img-max-size.service' ; import { ImgMaxPXSizeService } from './img-maxpx-size.service' ; import { ImgExifService } from './img-exif.service' ; @ Injectable ( ) export class Ng2ImgMaxService { constructor ( @ Inject ( forwardRef ( ( ) => ImgMaxSizeService ) ) private imgMaxSizeService , @ Inject ( forwardRef ( ( ) => ImgMaxPXSizeService ) ) private imgMaxPXSizeService , @ Inject ( forwardRef ( ( ) => ImgExifService ) ) private imageExifService ) { } public compress ( files , maxSizeInMB , ignoreAlpha = false , logExecutionTime = false ) { let compressedFileSubject = new Subject < any > ( ) ; files . forEach ( ( file ) => { this . compressImage ( file , maxSizeInMB , ignoreAlpha , logExecutionTime ) . subscribe ( ( value ) => { compressedFileSubject . next ( value ) ; } , error => { compressedFileSubject . error ( error ) ; } ) ; } ) ; return compressedFileSubject . asObservable ( ) ; } public resize ( files , maxWidth , maxHeight , logExecutionTime = false ) { let resizedFileSubject = new Subject < any > ( ) ; files . forEach ( ( file ) => { this . resizeImage ( file , maxWidth , maxHeight , logExecutionTime ) . subscribe ( ( value ) => { resizedFileSubject . next ( value ) ; } , error => { resizedFileSubject . error ( error ) ; } ) ; } ) ; return resizedFileSubject . asObservable ( ) ; } public compressImage ( file , maxSizeInMB , ignoreAlpha = false , logExecutionTime = false ) { return this . imgMaxSizeService . compressImage ( file , maxSizeInMB , ignoreAlpha , logExecutionTime ) ; } public resizeImage ( file , maxWidth , maxHeight , logExecutionTime = false ) { return this . imgMaxPXSizeService . resizeImage ( file , maxWidth , maxHeight , logExecutionTime ) ; } public getEXIFOrientedImage ( image ) { return this . imageExifService . getOrientedImage ( image ) ; } }