Skip to content

Commit

Permalink
error handling improved; fixes #5 preserve EXIF
Browse files Browse the repository at this point in the history
  • Loading branch information
bergben committed Mar 25, 2017
1 parent f3a825f commit 1cd5d91
Show file tree
Hide file tree
Showing 9 changed files with 951 additions and 74 deletions.
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,15 @@ Possible errors are: <br />
<b>`FILE_BIGGER_THAN_INITIAL_FILE`</b>: This should actually never happen, just a precaution. The `compressedFile` is the original file.<br />
<b>`UNABLE_TO_COMPRESS_ENOUGH`</b>: Could not compress image enough to fit the maximal file size limit. The `compressedFile` is a compression as close as it can get.<br />

Example code to show how to see if the result is an object (error happened) or a file:
Example code catch errors:

```TypeScript
this.ng2ImgMaxSerive.resize([someImage], 2000, 1000).subscribe((result)=>{
if (typeof result.name !== 'undefined' && typeof result.size !== 'undefined' && typeof result.type !== 'undefined') {
//all good, result is a file
console.info(result);
}
else {
//something went wrong
//use result.compressedFile or handle specific error cases individually
}
this.ng2ImgMaxSerive.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
});
```

Expand All @@ -83,6 +80,10 @@ Method to resize files if necessary down to a certain maximal width or maximal h
#### `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.
Expand Down
5 changes: 4 additions & 1 deletion ng2-img-max.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
export { Ng2ImgMaxService } from './src/ng2-img-max.service';
export { Ng2ImgMaxModule } from './src/ng2-img-max.module';
export { Ng2ImgMaxModule } from './src/ng2-img-max.module';
export { ImgMaxSizeService } from './src/img-max-size.service';
export { ImgMaxPXSizeService } from './src/img-maxpx-size.service';
export { ImgExifService } from './src/img-exif.service';
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ng2-img-max",
"version": "2.0.1",
"version": "2.1.0",
"description": "Angular 2 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.",
"repository": {
"type": "git",
Expand Down Expand Up @@ -34,6 +34,7 @@
},
"peerDependencies": {
"@angular/core": "^2.0.0",
"core-js": "^2.4.1",
"rxjs": "^5.0.0-beta.12"
},
"devDependencies": {
Expand Down
Loading

0 comments on commit 1cd5d91

Please sign in to comment.