Skip to content

Commit

Permalink
Merge pull request #187 from TonyBrobston/allow-determine-orientation…
Browse files Browse the repository at this point in the history
…-to-use-blob

feat: allow determineOrientation to use File or Blob
  • Loading branch information
TonyBrobston authored Nov 3, 2020
2 parents faa1275 + a42e75a commit ff8aa2a
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 45 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module.exports = {
## Documentation
**[compress](docs/modules/_index_.md#const-compress)**(`file`: File, `inputOptions`: [InputOptions](docs/interfaces/_types_inputoptions_.inputoptions.md)): *Promise‹File | Blob›*

**[determineOrientation](docs/modules/_index_.md#const-determineOrientation)**(`file`: File): *Promise‹number›*
**[determineOrientation](docs/modules/_index_.md#const-determineOrientation)**(`file`: File | Blob): *Promise‹number›*

## Caution
- Note that when the [`preserveFileType`](docs/interfaces/_types_inputoptions_.inputoptions.md#preservefiletype) option is `true`, the [`quality`](docs/interfaces/_types_inputoptions_.inputoptions.md#quality) option will only work for files such as `image/jpeg` and `image/webp` per the MDN web docs [here](https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toDataURL).
Expand Down
20 changes: 10 additions & 10 deletions docs/interfaces/_types_inputoptions_.inputoptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,76 +31,76 @@

`Optional` `Readonly` **allowCrossOriginResourceSharing**: undefined \| false \| true

*Defined in [types/InputOptions.ts:2](https://github.com/TonyBrobston/jpegasus/blob/ba960ee/src/types/InputOptions.ts#L2)*
*Defined in [types/InputOptions.ts:2](https://github.com/TonyBrobston/jpegasus/blob/faa1275/src/types/InputOptions.ts#L2)*

___

### fixImageOrientation

`Optional` `Readonly` **fixImageOrientation**: undefined \| false \| true

*Defined in [types/InputOptions.ts:3](https://github.com/TonyBrobston/jpegasus/blob/ba960ee/src/types/InputOptions.ts#L3)*
*Defined in [types/InputOptions.ts:3](https://github.com/TonyBrobston/jpegasus/blob/faa1275/src/types/InputOptions.ts#L3)*

___

### maxHeight

`Optional` `Readonly` **maxHeight**: undefined \| number

*Defined in [types/InputOptions.ts:10](https://github.com/TonyBrobston/jpegasus/blob/ba960ee/src/types/InputOptions.ts#L10)*
*Defined in [types/InputOptions.ts:10](https://github.com/TonyBrobston/jpegasus/blob/faa1275/src/types/InputOptions.ts#L10)*

___

### maxWidth

`Optional` `Readonly` **maxWidth**: undefined \| number

*Defined in [types/InputOptions.ts:11](https://github.com/TonyBrobston/jpegasus/blob/ba960ee/src/types/InputOptions.ts#L11)*
*Defined in [types/InputOptions.ts:11](https://github.com/TonyBrobston/jpegasus/blob/faa1275/src/types/InputOptions.ts#L11)*

___

### preserveFileType

`Optional` `Readonly` **preserveFileType**: undefined \| false \| true

*Defined in [types/InputOptions.ts:4](https://github.com/TonyBrobston/jpegasus/blob/ba960ee/src/types/InputOptions.ts#L4)*
*Defined in [types/InputOptions.ts:4](https://github.com/TonyBrobston/jpegasus/blob/faa1275/src/types/InputOptions.ts#L4)*

___

### quality

`Optional` `Readonly` **quality**: undefined \| number

*Defined in [types/InputOptions.ts:5](https://github.com/TonyBrobston/jpegasus/blob/ba960ee/src/types/InputOptions.ts#L5)*
*Defined in [types/InputOptions.ts:5](https://github.com/TonyBrobston/jpegasus/blob/faa1275/src/types/InputOptions.ts#L5)*

___

### returnOriginalIfCompressedFileIsLarger

`Optional` `Readonly` **returnOriginalIfCompressedFileIsLarger**: undefined \| false \| true

*Defined in [types/InputOptions.ts:7](https://github.com/TonyBrobston/jpegasus/blob/ba960ee/src/types/InputOptions.ts#L7)*
*Defined in [types/InputOptions.ts:7](https://github.com/TonyBrobston/jpegasus/blob/faa1275/src/types/InputOptions.ts#L7)*

___

### returnOriginalOnFailure

`Optional` `Readonly` **returnOriginalOnFailure**: undefined \| false \| true

*Defined in [types/InputOptions.ts:6](https://github.com/TonyBrobston/jpegasus/blob/ba960ee/src/types/InputOptions.ts#L6)*
*Defined in [types/InputOptions.ts:6](https://github.com/TonyBrobston/jpegasus/blob/faa1275/src/types/InputOptions.ts#L6)*

___

### scaleImageBy

`Optional` `Readonly` **scaleImageBy**: undefined \| number

*Defined in [types/InputOptions.ts:8](https://github.com/TonyBrobston/jpegasus/blob/ba960ee/src/types/InputOptions.ts#L8)*
*Defined in [types/InputOptions.ts:8](https://github.com/TonyBrobston/jpegasus/blob/faa1275/src/types/InputOptions.ts#L8)*

___

### transparencyFillColor

`Optional` `Readonly` **transparencyFillColor**: undefined \| string

*Defined in [types/InputOptions.ts:9](https://github.com/TonyBrobston/jpegasus/blob/ba960ee/src/types/InputOptions.ts#L9)*
*Defined in [types/InputOptions.ts:9](https://github.com/TonyBrobston/jpegasus/blob/faa1275/src/types/InputOptions.ts#L9)*
20 changes: 10 additions & 10 deletions docs/interfaces/_types_options_.options.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

*Overrides [InputOptions](_types_inputoptions_.inputoptions.md).[allowCrossOriginResourceSharing](_types_inputoptions_.inputoptions.md#allowcrossoriginresourcesharing)*

*Defined in [types/Options.ts:4](https://github.com/TonyBrobston/jpegasus/blob/ba960ee/src/types/Options.ts#L4)*
*Defined in [types/Options.ts:4](https://github.com/TonyBrobston/jpegasus/blob/faa1275/src/types/Options.ts#L4)*

___

Expand All @@ -43,7 +43,7 @@ ___

*Overrides [InputOptions](_types_inputoptions_.inputoptions.md).[fixImageOrientation](_types_inputoptions_.inputoptions.md#fiximageorientation)*

*Defined in [types/Options.ts:5](https://github.com/TonyBrobston/jpegasus/blob/ba960ee/src/types/Options.ts#L5)*
*Defined in [types/Options.ts:5](https://github.com/TonyBrobston/jpegasus/blob/faa1275/src/types/Options.ts#L5)*

___

Expand All @@ -53,7 +53,7 @@ ___

*Inherited from [InputOptions](_types_inputoptions_.inputoptions.md).[maxHeight](_types_inputoptions_.inputoptions.md#maxheight)*

*Defined in [types/InputOptions.ts:10](https://github.com/TonyBrobston/jpegasus/blob/ba960ee/src/types/InputOptions.ts#L10)*
*Defined in [types/InputOptions.ts:10](https://github.com/TonyBrobston/jpegasus/blob/faa1275/src/types/InputOptions.ts#L10)*

___

Expand All @@ -63,7 +63,7 @@ ___

*Inherited from [InputOptions](_types_inputoptions_.inputoptions.md).[maxWidth](_types_inputoptions_.inputoptions.md#maxwidth)*

*Defined in [types/InputOptions.ts:11](https://github.com/TonyBrobston/jpegasus/blob/ba960ee/src/types/InputOptions.ts#L11)*
*Defined in [types/InputOptions.ts:11](https://github.com/TonyBrobston/jpegasus/blob/faa1275/src/types/InputOptions.ts#L11)*

___

Expand All @@ -73,7 +73,7 @@ ___

*Overrides [InputOptions](_types_inputoptions_.inputoptions.md).[preserveFileType](_types_inputoptions_.inputoptions.md#preservefiletype)*

*Defined in [types/Options.ts:6](https://github.com/TonyBrobston/jpegasus/blob/ba960ee/src/types/Options.ts#L6)*
*Defined in [types/Options.ts:6](https://github.com/TonyBrobston/jpegasus/blob/faa1275/src/types/Options.ts#L6)*

___

Expand All @@ -83,7 +83,7 @@ ___

*Overrides [InputOptions](_types_inputoptions_.inputoptions.md).[quality](_types_inputoptions_.inputoptions.md#quality)*

*Defined in [types/Options.ts:7](https://github.com/TonyBrobston/jpegasus/blob/ba960ee/src/types/Options.ts#L7)*
*Defined in [types/Options.ts:7](https://github.com/TonyBrobston/jpegasus/blob/faa1275/src/types/Options.ts#L7)*

___

Expand All @@ -93,7 +93,7 @@ ___

*Overrides [InputOptions](_types_inputoptions_.inputoptions.md).[returnOriginalIfCompressedFileIsLarger](_types_inputoptions_.inputoptions.md#returnoriginalifcompressedfileislarger)*

*Defined in [types/Options.ts:9](https://github.com/TonyBrobston/jpegasus/blob/ba960ee/src/types/Options.ts#L9)*
*Defined in [types/Options.ts:9](https://github.com/TonyBrobston/jpegasus/blob/faa1275/src/types/Options.ts#L9)*

___

Expand All @@ -103,7 +103,7 @@ ___

*Overrides [InputOptions](_types_inputoptions_.inputoptions.md).[returnOriginalOnFailure](_types_inputoptions_.inputoptions.md#returnoriginalonfailure)*

*Defined in [types/Options.ts:8](https://github.com/TonyBrobston/jpegasus/blob/ba960ee/src/types/Options.ts#L8)*
*Defined in [types/Options.ts:8](https://github.com/TonyBrobston/jpegasus/blob/faa1275/src/types/Options.ts#L8)*

___

Expand All @@ -113,7 +113,7 @@ ___

*Overrides [InputOptions](_types_inputoptions_.inputoptions.md).[scaleImageBy](_types_inputoptions_.inputoptions.md#scaleimageby)*

*Defined in [types/Options.ts:10](https://github.com/TonyBrobston/jpegasus/blob/ba960ee/src/types/Options.ts#L10)*
*Defined in [types/Options.ts:10](https://github.com/TonyBrobston/jpegasus/blob/faa1275/src/types/Options.ts#L10)*

___

Expand All @@ -123,4 +123,4 @@ ___

*Overrides [InputOptions](_types_inputoptions_.inputoptions.md).[transparencyFillColor](_types_inputoptions_.inputoptions.md#transparencyfillcolor)*

*Defined in [types/Options.ts:11](https://github.com/TonyBrobston/jpegasus/blob/ba960ee/src/types/Options.ts#L11)*
*Defined in [types/Options.ts:11](https://github.com/TonyBrobston/jpegasus/blob/faa1275/src/types/Options.ts#L11)*
4 changes: 2 additions & 2 deletions docs/modules/_index_.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@

`Const` **determineOrientation**: [determineOrientation](_services_exifservice_.md#determineorientation) = exifService.determineOrientation

*Defined in [index.ts:30](https://github.com/TonyBrobston/jpegasus/blob/ba960ee/src/index.ts#L30)*
*Defined in [index.ts:30](https://github.com/TonyBrobston/jpegasus/blob/faa1275/src/index.ts#L30)*

## Functions

### compress

`Const`**compress**(`file`: File, `inputOptions`: [InputOptions](../interfaces/_types_inputoptions_.inputoptions.md)): Promise\<File \| Blob>

*Defined in [index.ts:8](https://github.com/TonyBrobston/jpegasus/blob/ba960ee/src/index.ts#L8)*
*Defined in [index.ts:8](https://github.com/TonyBrobston/jpegasus/blob/faa1275/src/index.ts#L8)*

#### Parameters:

Expand Down
6 changes: 3 additions & 3 deletions docs/modules/_services_canvasservice_.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

`Const`**correctExifRotation**(`context`: CanvasTransform, `orientation`: number, `height`: number, `width`: number): void

*Defined in [services/canvasService.ts:20](https://github.com/TonyBrobston/jpegasus/blob/ba960ee/src/services/canvasService.ts#L20)*
*Defined in [services/canvasService.ts:20](https://github.com/TonyBrobston/jpegasus/blob/faa1275/src/services/canvasService.ts#L20)*

#### Parameters:

Expand All @@ -37,7 +37,7 @@ ___

`Const`**create**(`file`: File, `image`: HTMLImageElement, `scale`: number, `__namedParameters`: { fixImageOrientation: boolean ; transparencyFillColor: string }): Promise\<HTMLCanvasElement>

*Defined in [services/canvasService.ts:48](https://github.com/TonyBrobston/jpegasus/blob/ba960ee/src/services/canvasService.ts#L48)*
*Defined in [services/canvasService.ts:48](https://github.com/TonyBrobston/jpegasus/blob/faa1275/src/services/canvasService.ts#L48)*

#### Parameters:

Expand All @@ -56,7 +56,7 @@ ___

`Const`**setCanvasDimensions**(`canvas`: HTMLCanvasElement, `orientation`: number, `fixImageOrientation`: boolean, `scaledHeight`: number, `scaledWidth`: number): void

*Defined in [services/canvasService.ts:4](https://github.com/TonyBrobston/jpegasus/blob/ba960ee/src/services/canvasService.ts#L4)*
*Defined in [services/canvasService.ts:4](https://github.com/TonyBrobston/jpegasus/blob/faa1275/src/services/canvasService.ts#L4)*

#### Parameters:

Expand Down
20 changes: 10 additions & 10 deletions docs/modules/_services_exifservice_.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,61 +26,61 @@

`Const` **applicationSegmentOneMarker**: 65505 = 65505

*Defined in [services/exifService.ts:1](https://github.com/TonyBrobston/jpegasus/blob/ba960ee/src/services/exifService.ts#L1)*
*Defined in [services/exifService.ts:1](https://github.com/TonyBrobston/jpegasus/blob/faa1275/src/services/exifService.ts#L1)*

___

### beginOfExifHeaderMarker

`Const` **beginOfExifHeaderMarker**: 1165519206 = 1165519206

*Defined in [services/exifService.ts:2](https://github.com/TonyBrobston/jpegasus/blob/ba960ee/src/services/exifService.ts#L2)*
*Defined in [services/exifService.ts:2](https://github.com/TonyBrobston/jpegasus/blob/faa1275/src/services/exifService.ts#L2)*

___

### byteOrderMarker

`Const` **byteOrderMarker**: 18761 = 18761

*Defined in [services/exifService.ts:3](https://github.com/TonyBrobston/jpegasus/blob/ba960ee/src/services/exifService.ts#L3)*
*Defined in [services/exifService.ts:3](https://github.com/TonyBrobston/jpegasus/blob/faa1275/src/services/exifService.ts#L3)*

___

### byteStuffingMarker

`Const` **byteStuffingMarker**: 65280 = 65280

*Defined in [services/exifService.ts:4](https://github.com/TonyBrobston/jpegasus/blob/ba960ee/src/services/exifService.ts#L4)*
*Defined in [services/exifService.ts:4](https://github.com/TonyBrobston/jpegasus/blob/faa1275/src/services/exifService.ts#L4)*

___

### orientationMarker

`Const` **orientationMarker**: 274 = 274

*Defined in [services/exifService.ts:5](https://github.com/TonyBrobston/jpegasus/blob/ba960ee/src/services/exifService.ts#L5)*
*Defined in [services/exifService.ts:5](https://github.com/TonyBrobston/jpegasus/blob/faa1275/src/services/exifService.ts#L5)*

___

### startOfFileMarker

`Const` **startOfFileMarker**: 65496 = 65496

*Defined in [services/exifService.ts:6](https://github.com/TonyBrobston/jpegasus/blob/ba960ee/src/services/exifService.ts#L6)*
*Defined in [services/exifService.ts:6](https://github.com/TonyBrobston/jpegasus/blob/faa1275/src/services/exifService.ts#L6)*

## Functions

### determineOrientation

`Const`**determineOrientation**(`file`: File): Promise\<number>
`Const`**determineOrientation**(`file`: File \| Blob): Promise\<number>

*Defined in [services/exifService.ts:36](https://github.com/TonyBrobston/jpegasus/blob/ba960ee/src/services/exifService.ts#L36)*
*Defined in [services/exifService.ts:36](https://github.com/TonyBrobston/jpegasus/blob/faa1275/src/services/exifService.ts#L36)*

#### Parameters:

Name | Type |
------ | ------ |
`file` | File |
`file` | File \| Blob |

**Returns:** Promise\<number>

Expand All @@ -90,7 +90,7 @@ ___

`Const`**parseBytes**(`dataView`: DataView, `resolve`: (uint16: number) => void): void

*Defined in [services/exifService.ts:8](https://github.com/TonyBrobston/jpegasus/blob/ba960ee/src/services/exifService.ts#L8)*
*Defined in [services/exifService.ts:8](https://github.com/TonyBrobston/jpegasus/blob/faa1275/src/services/exifService.ts#L8)*

#### Parameters:

Expand Down
4 changes: 2 additions & 2 deletions docs/modules/_services_fileservice_.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

`Const`**create**(`bytes`: Uint8Array[], `type`: string, `name`: string): File \| Blob

*Defined in [services/fileService.ts:9](https://github.com/TonyBrobston/jpegasus/blob/ba960ee/src/services/fileService.ts#L9)*
*Defined in [services/fileService.ts:9](https://github.com/TonyBrobston/jpegasus/blob/faa1275/src/services/fileService.ts#L9)*

#### Parameters:

Expand All @@ -35,7 +35,7 @@ ___

`Const`**validate**(`file`: File): boolean

*Defined in [services/fileService.ts:1](https://github.com/TonyBrobston/jpegasus/blob/ba960ee/src/services/fileService.ts#L1)*
*Defined in [services/fileService.ts:1](https://github.com/TonyBrobston/jpegasus/blob/faa1275/src/services/fileService.ts#L1)*

#### Parameters:

Expand Down
2 changes: 1 addition & 1 deletion docs/modules/_services_imageservice_.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

`Const`**create**(`file`: File, `options`: [Options](../interfaces/_types_options_.options.md)): Promise\<HTMLImageElement>

*Defined in [services/imageService.ts:3](https://github.com/TonyBrobston/jpegasus/blob/ba960ee/src/services/imageService.ts#L3)*
*Defined in [services/imageService.ts:3](https://github.com/TonyBrobston/jpegasus/blob/faa1275/src/services/imageService.ts#L3)*

#### Parameters:

Expand Down
2 changes: 1 addition & 1 deletion docs/modules/_services_optionservice_.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

`Const`**override**(`inputOptions`: [InputOptions](../interfaces/_types_inputoptions_.inputoptions.md)): [Options](../interfaces/_types_options_.options.md)

*Defined in [services/optionService.ts:4](https://github.com/TonyBrobston/jpegasus/blob/ba960ee/src/services/optionService.ts#L4)*
*Defined in [services/optionService.ts:4](https://github.com/TonyBrobston/jpegasus/blob/faa1275/src/services/optionService.ts#L4)*

#### Parameters:

Expand Down
2 changes: 1 addition & 1 deletion docs/modules/_services_qualityservice_.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

`Const`**toFile**(`file`: File, `canvas`: HTMLCanvasElement, `__namedParameters`: { preserveFileType: boolean ; quality: number }): File \| Blob

*Defined in [services/qualityService.ts:5](https://github.com/TonyBrobston/jpegasus/blob/ba960ee/src/services/qualityService.ts#L5)*
*Defined in [services/qualityService.ts:5](https://github.com/TonyBrobston/jpegasus/blob/faa1275/src/services/qualityService.ts#L5)*

#### Parameters:

Expand Down
4 changes: 2 additions & 2 deletions docs/modules/_services_scaleservice_.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

`Const`**determineScale**(`__namedParameters`: { height: number ; width: number }, `__namedParameters`: { maxHeight: undefined \| number ; maxWidth: undefined \| number ; scaleImageBy: number }): number

*Defined in [services/scaleService.ts:5](https://github.com/TonyBrobston/jpegasus/blob/ba960ee/src/services/scaleService.ts#L5)*
*Defined in [services/scaleService.ts:5](https://github.com/TonyBrobston/jpegasus/blob/faa1275/src/services/scaleService.ts#L5)*

#### Parameters:

Expand All @@ -34,7 +34,7 @@ ___

`Const`**toCanvas**(`file`: File, `options`: [Options](../interfaces/_types_options_.options.md)): Promise\<HTMLCanvasElement>

*Defined in [services/scaleService.ts:19](https://github.com/TonyBrobston/jpegasus/blob/ba960ee/src/services/scaleService.ts#L19)*
*Defined in [services/scaleService.ts:19](https://github.com/TonyBrobston/jpegasus/blob/faa1275/src/services/scaleService.ts#L19)*

#### Parameters:

Expand Down
2 changes: 1 addition & 1 deletion docs/modules/_services_windowservice_.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

`Const`**toByteArray**(`base64`: string): Uint8Array[]

*Defined in [services/windowService.ts:1](https://github.com/TonyBrobston/jpegasus/blob/ba960ee/src/services/windowService.ts#L1)*
*Defined in [services/windowService.ts:1](https://github.com/TonyBrobston/jpegasus/blob/faa1275/src/services/windowService.ts#L1)*

#### Parameters:

Expand Down
2 changes: 1 addition & 1 deletion src/services/exifService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const parseBytes = (dataView: DataView, resolve: (uint16: number) => void): void
resolve(-1);
};

const determineOrientation = async (file: File): Promise<number> => {
const determineOrientation = async (file: File|Blob): Promise<number> => {
return new Promise((resolve: (orientation: number) => void): void => {
try {
const reader = new FileReader();
Expand Down

0 comments on commit ff8aa2a

Please sign in to comment.