Giter Club home page Giter Club logo

ng2-img-max's Introduction

Join the chat at https://gitter.im/bergben/bergben

ng2-img-max

Angular 2 and beyond module to resize images down to a certain width and height or to reduce the quality to fit a certain maximal filesize - all in the browser.

This means, the huge image that the user may select will never even need to be uploaded to the server.

Demo

A simple demo is available on stackblitz: https://stackblitz.com/edit/angular-ivy-hnhy6v

Browser support

This module is supported by all major browsers recent versions (IE 10+).

Make sure to include the following polyfill for HtmlCanvasElement.toBlob(): https://www.npmjs.com/package/blueimp-canvas-to-blob

$ npm install blueimp-canvas-to-blob

Make sure to check out ng2-img-tools for further image manipulation such as resizing to an exact size (e.g. to create thumbnails) or image cropping as seen in the demo.

Install

$ npm install ng2-img-max

Import the module

Only needed for Angular versions prior to 13

// app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { Ng2ImgMaxModule } from 'ng2-img-max'; // <-- import the module
import { MyComponent } from './my.component';

@NgModule({
    imports: [BrowserModule,
              Ng2ImgMaxModule // <-- include it in your app module
             ],
    declarations: [MyComponent],  
    bootstrap: [MyComponent]
})
export class MyAppModule {}

Usage

import { Ng2ImgMaxService } from 'ng2-img-max';
[...]
    constructor(private ng2ImgMaxService: Ng2ImgMaxService) {
        this.ng2ImgMaxService.resize([someImage], 2000, 1000).subscribe((result)=>{
        });
    }
}

Methods

Maximal filesize

IMPORTANT: Catch error cases

When using the compression methods you should make sure to catch the error cases. If an error happens, you will receive an object with the following properties: compressedFile:File, reason: string and error:string

Possible errors are:
INVALID_EXTENSION: File provided is neither of type jpg nor of type png). The compressedFile is the original file.
PNG_WITH_ALPHA: File provided is a png image which uses the alpha channel. No compression possible unless ignoreAlpha is set to true. The compressedFile is the original file.
MAX_STEPS_EXCEEDED: Could not find the correct compression quality in 15 steps - abort. This should rarely to never at all happen. The compressedFile is the result of step 15 of the compression.
FILE_BIGGER_THAN_INITIAL_FILE: This should actually never happen, just a precaution. The compressedFile is the original file.
UNABLE_TO_COMPRESS_ENOUGH: Could not compress image enough to fit the maximal file size limit. The compressedFile is a compression as close as it can get.

Example code catch errors:

this.ng2ImgMaxService.resize([someImage], 2000, 1000).subscribe(result => {
   //all good, result is a file
   console.info(result);
}, error => {
   //something went wrong 
   //use result.compressedFile or handle specific error cases individually
});

compress(files: File[], maxSizeInMB: number, ignoreAlpha: boolean = false, logExecutionTime: boolean = false): Observable<any>

Method to compress an image. This reduces the quality of an image down until it fits a certain fileSize which is given as maxSizeInMB. Set ignoreAlpha to true if you want to ignore the alpha channel for png images and compress them nonetheless (not recommended - the alpha channel will be lost and the resulting image might differ from the original image). Returns an observable that for every file given, onNext receives either a File when everything went as planned or an error Object if something went wrong.

compressImage

Same as above just that it takes in only one file instead of a whole array of files.

Maximal width / height

resize(files: File[], maxWidth: number, maxHeight: number, logExecutionTime: boolean = false): Observable<any>

Method to resize files if necessary down to a certain maximal width or maximal height in px. If you want only one limit just set the other max to 10.000: for example resize([myfile1,myfile2],2000,10000).subscribe([...]

resizeImage

Same as above just that it takes in only one file instead of a whole array of files.

Get EXIF oriented image

getEXIFOrientedImage(image:HTMLImageElement): Promise<HTMLImageElement>

Method that returns an image respecting the EXIF orientation data.

Contribute

Due to the lack of other algorithms that also reduce the filesize of an image by reducing the quality until it fits a certain limit, help to find the best possible algorithm to do so is much appreciated. The current algorithm can be found here: https://github.com/bergben/ng2-img-max/blob/master/src/img-max-size.service.ts.

Limitations

Although the resizing functions do use web workers to do the heavy work, this is not possible for the compression methods. The reasons for this are that a web worker does not have access to the DOM and can therefor not create a new HtmlCanvasElement. Neither can it be passed as a parameter to the web worker, as a web worker can only receive serializable data, which only be the ImageData but that can only be turned into a 2DCanvasContext, not a HtmlCanvasElement itself without the DOM.

ng2-img-max's People

Contributors

bergben avatar cbstodd avatar davi01100100 avatar dfa1234 avatar flowwwww avatar jdmaldonado avatar mikekovarik avatar prashantguleria avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ng2-img-max's Issues

Error compiling app

Hello, I'm having this error with new version when starting my app:

ERROR in ./node_modules/ng2-img-max/dist/src/ng2-img-max.module.js
Module not found: Error: Can't resolve 'ng2-pica/ng2-pica' in '/home/luis/Desktop/Dev/Code/app/node_modules/ng2-img-max/dist/src'
ERROR in ./node_modules/ng2-img-max/dist/src/img-maxpx-size.service.js
Module not found: Error: Can't resolve 'ng2-pica/ng2-pica' in '/home/luis/Desktop/Dev/Code/rapp/node_modules/ng2-img-max/dist/src'

2.1.15 works fine, Angular 6.

Thanks

Runtime error in 2.1.17

Error when running with 2.1.17
2.1.15 with ng2-pica 1.2.8 no issue

core.js:1673 ERROR Error: Uncaught (in promise): ReferenceError: EXIF is not defined
ReferenceError: EXIF is not defined
at img-exif.service.js:9
at new ZoneAwarePromise (zone.js:891)
at ImgExifService.push../node_modules/ng2-img-max/dist/src/img-exif.service.js.ImgExifService.getOrientedImage (img-exif.service.js:7)
at Image.img.onload [as __zone_symbol__ON_PROPERTYload] (img-maxpx-size.service.js:25)
at Image.wrapFn (zone.js:1188)
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:421)
at Object.onInvokeTask (core.js:3815)
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:420)
at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:188)
at ZoneTask.push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask [as invoke] (zone.js:496)
at img-exif.service.js:9
at new ZoneAwarePromise (zone.js:891)
at ImgExifService.push../node_modules/ng2-img-max/dist/src/img-exif.service.js.ImgExifService.getOrientedImage (img-exif.service.js:7)
at Image.img.onload [as __zone_symbol__ON_PROPERTYload] (img-maxpx-size.service.js:25)
at Image.wrapFn (zone.js:1188)
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:421)
at Object.onInvokeTask (core.js:3815)
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:420)
at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:188)
at ZoneTask.push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask [as invoke] (zone.js:496)
at resolvePromise (zone.js:814)
at resolvePromise (zone.js:771)
at zone.js:873
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:421)
at Object.onInvokeTask (core.js:3815)
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:420)
at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:188)
at drainMicroTaskQueue (zone.js:595)
at ZoneTask.push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask [as invoke] (zone.js:500)
at invokeTask (zone.js:1540)

Issue with compress method, to compress multiple images.

I've been using compress method to compress mutiples images by passing an array of files, but the method is responding to the last image only.

this.ngxImgMaxService.compress(files, 0.1).subscribe(
      result => {
        let uploadedImage = new File([result], result.name);
        console.log(uploadedImage);
      },
      error => {
        console.log('😒 Oh no!', error);
      }
 );

File Type Question

this.ng2ImgMaxService.resizeImage( IMAGE_FILE_HERE , 2000, 1000)

Can IMAGE_FILE_HERE be an image data uri such as data:image/jpeg;base64,/-- string information --?

Remap Exif-JS Usage Until Updated

The most current version of exif-js is 2.3.0 and was updated years ago. However, the version was uploaded with the following bug: exif-js/exif-js#214

As a result, ng2-img-max also will hit that issue when uploading some files. I have fixed this issue in my local by forking the current state of exif-js and adding it to my package manifest as a git repo instead, so that the "undefined n" issue is fixed.

ng2-img-max should either make the same decision and commit the changes or look for an alternative exif library, as it appears the issue will not be fixed in exif-js any time soon (the last update was over a year ago)

Should latest release retain EXIF data when using the max resize function/feature?

I realize this is not maintained any more so I am trying to trouble-shoot. I just wanted to know if it should be working or if it hasn't been integrated yet. I am simply trying to resize image against a file using the max image size approach( e.g. this.ng2ImgMax.resizeImage(theFile, maxWidth, maxHeight) ) Should the object I get back retain the exif data using this function?

Thanks

ng2-img-max not working with Angular 9

ERROR ReferenceError: n is not defined
at getStringFromDB (exif.js:741)
at readEXIFData (exif.js:748)
at findEXIFinJPEG (exif.js:449)
at handleBinaryFile (exif.js:370)
at FileReader.fileReader.onload (exif.js:391)
at ZoneDelegate.invoke (zone-evergreen.js:365)
at Object.onInvoke (core.js:40794)
at ZoneDelegate.invoke (zone-evergreen.js:364)
at Zone.runGuarded (zone-evergreen.js:134)
at FileReader. (zone-evergreen.js:118)

Demo App doesn't work in IE11

steps:

  1. run the demo app in IE11
  2. upload .jpeg file
    the result:

image

the following error apears in the browser console:

ERROR Error: macroTask 'HTMLCanvasElement.toBlob': can not transition to 'running', expecting state 'scheduled', was 'scheduling'.

Metadata mismatch

Tried to fire up my app this morning but I have got this error:

ERROR in Error: Metadata version mismatch for module /Users/eddwdev/Desktop/Herts/staff-directory/node_modules/ng2-img-max/dist/ng2-img-max.d.ts, found version 4, expected 3, resolving symbol AppModule in /Users/eddwdev/Desktop/Herts/staff-directory/src/app/app.module.ts, resolving symbol AppModule in /Users/eddwdev/Desktop/Herts/staff-directory/src/app/app.module.ts at Error (native) at syntaxError (/Users/eddwdev/Desktop/Herts/staff-directory/node_modules/@angular/compiler/bundles/compiler.umd.js:1729:34) at simplifyInContext (/Users/eddwdev/Desktop/Herts/staff-directory/node_modules/@angular/compiler/bundles/compiler.umd.js:24979:23) at StaticReflector.simplify (/Users/eddwdev/Desktop/Herts/staff-directory/node_modules/@angular/compiler/bundles/compiler.umd.js:24991:13) at StaticReflector.annotations (/Users/eddwdev/Desktop/Herts/staff-directory/node_modules/@angular/compiler/bundles/compiler.umd.js:24418:41) at _getNgModuleMetadata (/Users/eddwdev/Desktop/Herts/staff-directory/node_modules/@angular/compiler-cli/src/ngtools_impl.js:138:31) at _extractLazyRoutesFromStaticModule (/Users/eddwdev/Desktop/Herts/staff-directory/node_modules/@angular/compiler-cli/src/ngtools_impl.js:109:26) at Object.listLazyRoutesOfModule (/Users/eddwdev/Desktop/Herts/staff-directory/node_modules/@angular/compiler-cli/src/ngtools_impl.js:53:22) at Function.NgTools_InternalApi_NG_2.listLazyRoutes (/Users/eddwdev/Desktop/Herts/staff-directory/node_modules/@angular/compiler-cli/src/ngtools_api.js:91:39) at AotPlugin._getLazyRoutesFromNgtools (/Users/eddwdev/Desktop/Herts/staff-directory/node_modules/@ngtools/webpack/src/plugin.js:207:44) at _donePromise.Promise.resolve.then.then.then.then.then (/Users/eddwdev/Desktop/Herts/staff-directory/node_modules/@ngtools/webpack/src/plugin.js:443:24) at process._tickCallback (internal/process/next_tick.js:109:7)

Not sure if anyone else has got this error/solution? I have tried setting my typescript version to the same as the dev dependancy but no luck with that.

Just update to v2.1.7 and the found some error

I got the error from my angular app, which just an update for today. Can not find any reference one for now.

Error: Unexpected value 'Ng2ImgMaxModule' imported by the module 'AppModule'. Please add a @NgModule annotation

Error while uploading Angular 4 server with npm start

Hey guys!

I tried to use the ng2-img-max yesterday, and all run smoothly, but then when I cloned my repo again and tried, it failed with the error:

ERROR in Error: Metadata version mismatch for module /Users/victordeassis/Documents/GitHub/easygamermvp/node_modules/ng2-img-tools/dist/ng2-img-tools.d.ts, found version 4, expected 3, resolving symbol AppModule in /Users/victordeassis/Documents/GitHub/easygamermvp/src/app/app.module.ts, resolving symbol AppModule in /Users/victordeassis/Documents/GitHub/easygamermvp/src/app/app.module.ts

Can you guys help me to solve this?

Not working on mobile

My simple implementation using resize method is making the browser crash on android. Is this tested on mobile? Any memory limitations?

Andoid Chrome browser freezes when using compress

In my android phone of 4GB ram, when I upload an image and compress it using below code

onImageChange(event) {
  let image = event.target.files[0];

  this.ng2ImgMax.compressImage(image, 0.25).subscribe(
    result => {
      this.uploadedImage = new File([result], result.name);
      this.getImagePreview(this.uploadedImage);
    },
    error => {
      console.log('😒 Oh no!', error);
    }
  );
}

Referenced from this article: https://alligator.io/angular/resizing-images-in-browser-ng2-img-max/ Compress Instead of Resizing

When uploading an image of 3.5 MB, getting the compressed image of 200-500 kb. That is good but the browser is freezing for 8-15 secs.

Though this is not an issue in laptop or desktop browser.

Suggestion for handling alpha channels

Would it be possible to add a feature to compress images with alpha channels and convert it to white?

Not sure how feasible it would be, so feel free to take this with a grain of salt. (Loving the package otherwise)

Angular5 compatibility with build optimizer

In order to be compatible with angular5 and angular cli v1.5.0-rc.8 (new build optimizer) some files of the ng2-img-max must be modified.

FILES:
ng2-img-max.service
img-max-size.service
img-maxpx-size.service

FIX:

// import { Observable } from 'rxjs'; // bug: build optimizer
// import { Subject } from 'rxjs'; // bug: build optimizer
// import { Subject } from 'rxjs/Subject'; // ng5 fix
// import { Observable } from 'rxjs/Observable'; // ng5 fix
// import { BehaviorSubject } from 'rxjs/BehaviorSubject'; // ng5 fix

PACKAGE.JSON

"dependencies": {
    "@angular/animations": "^5.0.0",
    "@angular/common": "^5.0.0",
    "@angular/compiler": "^5.0.0",
    "@angular/core": "^5.0.0",
    "@angular/forms": "^5.0.0",
    "@angular/http": "^5.0.0",
    "@angular/platform-browser": "^5.0.0",
    "@angular/platform-browser-dynamic": "^5.0.0",
    "@angular/router": "^5.0.0",
    "@ngui/auto-complete": "^0.16.0",
    "@ngx-translate/core": "^8.0.0",
    "@ngx-translate/http-loader": "2.0.0",
    "@ultimate/ngxerrors": "^1.3.0",
    "angular2-moment": "^1.7.0",
    "blueimp-canvas-to-blob": "^3.14.0",
    "core-js": "^2.5.1",
    "ng2-auto-complete": "^0.12.0",
    "ng2-img-max": "^2.1.6",
    "ng2-toastr": "^4.1.2",
    "ngx-bootstrap": "^v2.0.0-beta.7",
    "ngx-img-fallback": "^1.2.0",
    "ngx-infinite-scroll": "^0.6.1",
    "ngx-progressbar": "^2.1.1",
    "rxjs": "5.5.2",
    "ts-helpers": "^1.1.2",
    "zone.js": "^0.8.18"
  },
  "devDependencies": {
    "@angular/cli": "^v1.5.0-rc.8",
    "@angular/compiler-cli": "^5.0.0",
    "@types/jasmine": "2.6.2",
    "@types/node": "^8.0.47",
    "codelyzer": "~3.2.2",
    "jasmine-core": "2.8.0",
    "jasmine-spec-reporter": "4.2.1",
    "karma": "1.7.1",
    "karma-chrome-launcher": "^2.2.0",
    "karma-cli": "^1.0.1",
    "karma-jasmine": "^1.1.0",
    "karma-remap-istanbul": "^0.6.0",
    "protractor": "5.2.0",
    "ts-node": "3.3.0",
    "tslint": "^5.8.0",
    "typescript": "~2.4.2",
    "webdriver-manager": "12.0.6"
  }

ReferenceError: window is not defined

When i use universal for ssr i have this error:
/node_modules/bergben-pica/dist/bundles/bergben-pica.umd.js:120
window.pica = exports;
ReferenceError: window is not defined

ng build : img-exif version 3 expected

Hello,
I have a bug when I try to build my project with angular-cli.

ng build

return this error :

Metada version mismatch for module img-exif.service.d.ts found version 4, expected 3

Images get a black marks

When I resize some images, they get a black marks.
I don't know why... seems random to me.

Do you have any idea what might be causing this?

Here are some examples:

original:
image

resized:
image

original:
image

resized:
image

original:
image

resized:
image

Update to Angular 12

Error to build
./node_modules/ng2-img-max/dist/src/img-exif.service.js:13:6-23 - Error: export 'orientation' (imported as 'exifr') was not found in 'exifr/dist/mini.legacy.umd' (module has no exports)

Resizing is not working on IOS

Hello,
Nice library, but I have an issue only on IOS (Safari and Chrome)
(it works like a charm on Windows Firefox/Chrome and Mac Safari).

Here is my code :

  public backgroundImage: string = null;

  public setBackgroundImg() {

    let xhr = new XMLHttpRequest();
    xhr.open('GET', (this.platformLocation as any).location.href+'/assets/background4.jpg', true);
    xhr.responseType = 'blob';

    xhr.onload = (e) => {
      console.log('xhr.onload OK', e, xhr);
      
      if (xhr.status == 200) {
        let blob = xhr.response;
        let size = Math.max(window.screen.width, window.screen.height);
        console.log('xhr.status=200 OK', blob, size);

        this.ng2ImgMaxService.resize([blob], size, size).subscribe( result => {
          console.log('ng2ImgMaxService.resize', result);

          this.backgroundImage = this.sanitizer.bypassSecurityTrustStyle('url('+window.URL.createObjectURL(result)+')');
        });
      }
    };
    xhr.send();
  }

Here is the trace :

- xhr.onload OK

- xhr.status=200 OK

- [Error] ERROR
Error: Uncaught (in promise): [object Object]
resolvePromise β€” zone.js:824
(fonction anonyme) β€” zone.js:876
onInvokeTask β€” core.es5.js:3881
runTask β€” zone.js:192
drainMicroTaskQueue β€” zone.js:602
invokeTask β€” zone.js:503
invokeTask β€” zone.js:1540
globalZoneAwareCallback β€” zone.js:1566
	defaultErrorLogger (vendor.bundle.js:79023)
	handleError (vendor.bundle.js:79083)
	next (vendor.bundle.js:82506:148)
	(fonction anonyme) (vendor.bundle.js:81638)
	__tryOrUnsub (vendor.bundle.js:24462)
	next (vendor.bundle.js:24409)
	_next (vendor.bundle.js:24349)
	next (vendor.bundle.js:24313)
	next (vendor.bundle.js:24057)
	emit (vendor.bundle.js:81624)
	run (polyfills.bundle.js:2687)
	onHandleError (vendor.bundle.js:81915)
	runGuarded (polyfills.bundle.js:2703)
	_loop_1 (polyfills.bundle.js:3247)
	microtaskDrainDone (polyfills.bundle.js:3256)
	drainMicroTaskQueue (polyfills.bundle.js:3155)
	invokeTask (polyfills.bundle.js:3048)
	invokeTask (polyfills.bundle.js:4085)
	globalZoneAwareCallback (polyfills.bundle.js:4111)

Any idea ?

Resize fails after Pica gets updated beyond 4.0.1

The Plunkr is also currently broken due to this.

If Pica gets to 4.1.0 - the resizing will fail:

Resize exact crop error: {resizedFile: File(1486333), reason: TypeError: Cannot read property 'toBlob' of undefined at eval (https://unpkg.com/ng2-pica/dist/b…, error: "PICA_ERROR"}

To fix this, one can manually install Pica 4.0.1 instead. Will work again.

Preserve EXIF image orientation

EXIF image orientation data appears to be lost on resize/compress. This causes incorrect display of the image. It would be great if there was an option to preserve EXIF data.

Thanks for this useful module.

"exif-js": "^2.3.0" causes Uncaught (in promise): ReferenceError: EXIF is not defined ReferenceError: EXIF is not defined

Latest exif-js (specified as dependency)causes errors when using ng2-img-max resizing method.
Reprosteps - resize bigger images 4-5MB

ReferenceError: EXIF is not defined
    at eval (webpack:///./~/ng2-pica/dist/src/img-exif.service.js?:13)
    at new ZoneAwarePromise (webpack:///./~/zone.js/dist/zone.js?:834)
    at ImgExifService.getOrientedImage (webpack:///./~/ng2-pica/dist/src/img-exif.service.js?:11)
    at Image.img.onload (webpack:///./~/ng2-pica/dist/src/ng2-pica.service.js?:66)
    at Image.wrapFn [as __zone_symbol___onload] (webpack:///./~/zone.js/dist/zone.js?:1056)
    at ZoneDelegate.invokeTask (webpack:///./~/zone.js/dist/zone.js?:424)
    at Object.onInvokeTask (webpack:///./~/@angular/core/@angular/core.es5.js?:4128)
    at ZoneDelegate.invokeTask (webpack:///./~/zone.js/dist/zone.js?:423)
    at Zone.runTask (webpack:///./~/zone.js/dist/zone.js?:191)
    at Image.ZoneTask.invoke (webpack:///./~/zone.js/dist/zone.js?:486)
    at Image.c (newrelic.min.js:1)
    at eval (webpack:///./~/ng2-pica/dist/src/img-exif.service.js?:13)
    at new ZoneAwarePromise (webpack:///./~/zone.js/dist/zone.js?:834)
    at ImgExifService.getOrientedImage (webpack:///./~/ng2-pica/dist/src/img-exif.service.js?:11)
    at Image.img.onload (webpack:///./~/ng2-pica/dist/src/ng2-pica.service.js?:66)
    at Image.wrapFn [as __zone_symbol___onload] (webpack:///./~/zone.js/dist/zone.js?:1056)
    at ZoneDelegate.invokeTask (webpack:///./~/zone.js/dist/zone.js?:424)
    at Object.onInvokeTask (webpack:///./~/@angular/core/@angular/core.es5.js?:4128)
    at ZoneDelegate.invokeTask (webpack:///./~/zone.js/dist/zone.js?:423)
    at Zone.runTask (webpack:///./~/zone.js/dist/zone.js?:191)
    at Image.ZoneTask.invoke (webpack:///./~/zone.js/dist/zone.js?:486)
    at Image.c (newrelic.min.js:1)
    at resolvePromise (webpack:///./~/zone.js/dist/zone.js?:770)
    at resolvePromise (webpack:///./~/zone.js/dist/zone.js?:741)
    at eval (webpack:///./~/zone.js/dist/zone.js?:818)
    at ZoneDelegate.invokeTask (webpack:///./~/zone.js/dist/zone.js?:424)
    at Object.onInvokeTask (webpack:///./~/@angular/core/@angular/core.es5.js?:4128)
    at ZoneDelegate.invokeTask (webpack:///./~/zone.js/dist/zone.js?:423)
    at Zone.runTask (webpack:///./~/zone.js/dist/zone.js?:191)
    at drainMicroTaskQueue (webpack:///./~/zone.js/dist/zone.js?:584)
    at Image.ZoneTask.invoke (webpack:///./~/zone.js/dist/zone.js?:490)
    at Image.c (newrelic.min.js:1)
    at ____________________Elapsed_6_ms__At__Thu_Aug_16_2018_14_18_39_GMT_0200__Central_European_Summer_Time_ ()
    at Object.onScheduleTask (webpack:///./~/zone.js/dist/long-stack-trace-zone.js?:109)
    at ZoneDelegate.scheduleTask (webpack:///./~/zone.js/dist/zone.js?:404)
    at Object.onScheduleTask (webpack:///./~/zone.js/dist/zone.js?:300)
    at ZoneDelegate.scheduleTask (webpack:///./~/zone.js/dist/zone.js?:404)
    at Zone.scheduleTask (webpack:///./~/zone.js/dist/zone.js?:235)
    at Zone.scheduleMicroTask (webpack:///./~/zone.js/dist/zone.js?:255)
    at scheduleResolveOrReject (webpack:///./~/zone.js/dist/zone.js?:816)
    at ZoneAwarePromise.then (webpack:///./~/zone.js/dist/zone.js?:905)
    at Image.img.onload (webpack:///./~/ng2-pica/dist/src/ng2-pica.service.js?:66)
    at Image.wrapFn [as __zone_symbol___onload] (webpack:///./~/zone.js/dist/zone.js?:1056)
    at ZoneDelegate.invokeTask (webpack:///./~/zone.js/dist/zone.js?:424)
    at Object.onInvokeTask (webpack:///./~/@angular/core/@angular/core.es5.js?:4128)
    at ZoneDelegate.invokeTask (webpack:///./~/zone.js/dist/zone.js?:423)
    at Zone.runTask (webpack:///./~/zone.js/dist/zone.js?:191)
    at Image.ZoneTask.invoke (webpack:///./~/zone.js/dist/zone.js?:486)
    at Image.c (newrelic.min.js:1)
    at ____________________Elapsed_182_ms__At__Thu_Aug_16_2018_14_18_39_GMT_0200__Central_European_Summer_Time_ ()
    at Object.onScheduleTask (webpack:///./~/zone.js/dist/long-stack-trace-zone.js?:109)
    at ZoneDelegate.scheduleTask (webpack:///./~/zone.js/dist/zone.js?:404)
    at Object.onScheduleTask (webpack:///./~/zone.js/dist/zone.js?:300)
    at ZoneDelegate.scheduleTask (webpack:///./~/zone.js/dist/zone.js?:404)
    at Zone.scheduleTask (webpack:///./~/zone.js/dist/zone.js?:235)
    at Zone.scheduleEventTask (webpack:///./~/zone.js/dist/zone.js?:261)
    at zoneAwareAddListener (webpack:///./~/zone.js/dist/zone.js?:1279)
    at Image.proto.(anonymous function) [as addEventListener] (webpack:///./~/zone.js/dist/zone.js?:1426:20)
    at Image.desc.set [as onload] (webpack:///./~/zone.js/dist/zone.js?:1063)
    at eval (webpack:///./~/ng2-pica/dist/src/ng2-pica.service.js?:65)
    at new ZoneAwarePromise (webpack:///./~/zone.js/dist/zone.js?:834)
    at Ng2PicaService.resizeFile (webpack:///./~/ng2-pica/dist/src/ng2-pica.service.js?:61)
    at Ng2PicaService.resize (webpack:///./~/ng2-pica/dist/src/ng2-pica.service.js?:20)
    at eval (webpack:///./~/ng2-img-max/dist/src/img-maxpx-size.service.js?:65)
    at ZoneDelegate.invoke (webpack:///./~/zone.js/dist/zone.js?:391)
    at Object.onInvoke (webpack:///./~/@angular/core/@angular/core.es5.js?:4137)
    at ZoneDelegate.invoke (webpack:///./~/zone.js/dist/zone.js?:390)
    at Zone.run (webpack:///./~/zone.js/dist/zone.js?:141)
    at eval (webpack:///./~/zone.js/dist/zone.js?:818)
    at ZoneDelegate.invokeTask (webpack:///./~/zone.js/dist/zone.js?:424)
    at Object.onInvokeTask (webpack:///./~/@angular/core/@angular/core.es5.js?:4128)
    at ZoneDelegate.invokeTask (webpack:///./~/zone.js/dist/zone.js?:423)
    at Zone.runTask (webpack:///./~/zone.js/dist/zone.js?:191)
    at drainMicroTaskQueue (webpack:///./~/zone.js/dist/zone.js?:584)
    at ____________________Elapsed_4_ms__At__Thu_Aug_16_2018_14_18_39_GMT_0200__Central_European_Summer_Time_ ()
    at Object.onScheduleTask (webpack:///./~/zone.js/dist/long-stack-trace-zone.js?:109)
    at ZoneDelegate.scheduleTask (webpack:///./~/zone.js/dist/zone.js?:404)
    at Object.onScheduleTask (webpack:///./~/zone.js/dist/zone.js?:300)
    at ZoneDelegate.scheduleTask (webpack:///./~/zone.js/dist/zone.js?:404)
    at Zone.scheduleTask (webpack:///./~/zone.js/dist/zone.js?:235)
    at Zone.scheduleMicroTask (webpack:///./~/zone.js/dist/zone.js?:255)
    at scheduleResolveOrReject (webpack:///./~/zone.js/dist/zone.js?:816)
    at resolvePromise (webpack:///./~/zone.js/dist/zone.js?:765)
    at eval (webpack:///./~/zone.js/dist/zone.js?:696)
    at Image.eval (webpack:///./~/ng2-img-max/dist/src/img-exif.service.js?:64)
    at handleBinaryFile (webpack:///./~/ng2-img-max/dist/src/exif.js?:95)
    at FileReader.fileReader_1.onload (webpack:///./~/ng2-img-max/dist/src/exif.js?:107)
    at ZoneDelegate.invoke (webpack:///./~/zone.js/dist/zone.js?:391)
    at Object.onInvoke (webpack:///./~/@angular/core/@angular/core.es5.js?:4137)
    at ZoneDelegate.invoke (webpack:///./~/zone.js/dist/zone.js?:390)
    at Zone.runGuarded (webpack:///./~/zone.js/dist/zone.js?:154)
    at FileReader.eval (webpack:///./~/zone.js/dist/zone.js?:132)

Migration to exifr lost PNG support

Hello, I am receiving a "Unknown file format" when using this with some PNG files. My guess is it works if there is no need to compress the PNG passed, but crashes otherswise.

The error comes from exifr, and there is an open issue to allow for PNGs : MikeKovarik/exifr#19

I suggest we just skip the exif read if it is a png for now?

DOC typo error

I think It should be service, that all :) if you have time, you can fix this
image

Update to [email protected] and [email protected]

Summary

I'm submitting a:

  • bug report
  • feature request
  • question / support request
  • other

Description

Necessary to compatibility of import paths to new structure.
image

Demo

Lib versions:

Angular CLI: 6.0.0
Node: 8.11.1
OS: win32 x64
Angular: 6.0.0
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, material, platform-browser
... platform-browser-dynamic, platform-server, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.6.0
@angular-devkit/build-angular     0.6.0
@angular-devkit/build-optimizer   0.6.0
@angular-devkit/core              0.6.0
@angular-devkit/schematics        0.6.0
@angular/cdk                      5.2.5
@angular/http                     5.2.10
@ngtools/webpack                  6.0.0
@schematics/angular               0.6.0
@schematics/update                0.6.0
rxjs                              6.1.0
typescript                        2.7.2
webpack                           4.6.0

PICA_ERROR when trying to resize PNG files

Hi can you please check your stackblitz demo?
It is cause error when I try to resize a png screenshot.
Resize error:
{resizedFile: {…}, reason: {…}, error: "PICA_ERROR"}
error: "PICA_ERROR"

Thanks!

INVALID_EXTENSION - .jpg

When I try to resize/compress a .jpg file from an android device, I keep getting "INVALID_EXTENSION" error. But for .png, or .jpeg files works fine.

Output:

Input image
Blob(225073)Β {size: 225073, type: "image/jpg"} size: 225073 type: "image/jpg" __proto__: Blob
Output error
{compressedFile: Blob(225073), reason: "File provided is neither of type jpg nor of type png.", error: "INVALID_EXTENSION"} {resizedFile: Blob(225073), reason: "The provided File is neither of type jpg nor of type png.", error: "INVALID_EXTENSION"}

No provider for ........Service

Hi,
After installing this library in my project and trying to call .compressImage, I got multiple exceptions.

No provider for ImgMaxSizeService
No provider for ImgExifService
No provider for ImgMaxPXSizeService

Now I could fix all these by setting them in the providers block in my @NgModule declaration

The problem I encounter now is that it complains:

No provider for Ng2PicaService

Which is not a class exported by the library. How can I fix this issue?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.