@eris/image
Advanced tools
Comparing version 0.1.1-alpha.1 to 0.1.1-alpha.2
@@ -7,3 +7,4 @@ import { BufferLike, IMetadata } from './types'; | ||
private readonly _metadata; | ||
constructor(image: Promise<IAnnotatedImageData> | IAnnotatedImageData, metadata?: object); | ||
constructor(image: Promise<IAnnotatedImageData> | IAnnotatedImageData, metadata?: Partial<IMetadata>); | ||
private _applyEXIFOrientation; | ||
private _applyResize; | ||
@@ -15,4 +16,4 @@ private _applyGreyscale; | ||
toBuffer(): Promise<BufferLike>; | ||
protected static _fromBuffer(buffer: BufferLike, metadata?: object): Image; | ||
protected static _fromBuffer(buffer: BufferLike, metadata?: Partial<IMetadata>): Image; | ||
protected static _fromImageData(imageData: IAnnotatedImageData): Image; | ||
} |
@@ -22,2 +22,26 @@ "use strict"; | ||
} | ||
_applyEXIFOrientation(image) { | ||
const exif = this._metadata && this._metadata.exif; | ||
if (!exif || !exif._raw.Orientation) { | ||
return image; | ||
} | ||
/** @see https://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/EXIF.html */ | ||
switch (exif._raw.Orientation) { | ||
case 1: | ||
// Do nothing | ||
break; | ||
case 3: | ||
image = image_data_1.ImageData.rotate(image, 180); | ||
break; | ||
case 6: | ||
image = image_data_1.ImageData.rotate(image, 270); // our rotate is CCW so 360 - 90 | ||
break; | ||
case 8: | ||
image = image_data_1.ImageData.rotate(image, 90); // our rotate is CCW so 360 - 270 | ||
break; | ||
default: | ||
throw new Error(`Unable to handle orientation ${exif._raw.Orientation}`); | ||
} | ||
return image; | ||
} | ||
_applyResize(image) { | ||
@@ -48,2 +72,3 @@ if (!this._output.resize) { | ||
let image = yield imagePromise; | ||
image = yield this._applyEXIFOrientation(image); | ||
image = yield this._applyGreyscale(image); | ||
@@ -50,0 +75,0 @@ image = yield this._applyResize(image); |
@@ -46,2 +46,6 @@ import { Colorspace, BufferLike, IPixel, ColorChannel, IFormatOptions, ICalibrationProfile, IPixelCoordinate, IGreyscalePixel, MapPixelFn } from './types'; | ||
static rotateArray(srcArray: number[] | Uint8Array, dstArray: number[] | Uint8Array, width: number, height: number, angle: number, channels?: number): void; | ||
/** | ||
* Rotates the image data counter-clockwise by the specified angle. | ||
* TODO: convert this to clockwise rotation | ||
*/ | ||
static rotate(srcImageData: IAnnotatedImageData, angle: number): IAnnotatedImageData; | ||
@@ -48,0 +52,0 @@ static proximityTransform(imageData: IAnnotatedImageData, adjustments: IProximityAdjustment[]): IAnnotatedImageData; |
@@ -214,2 +214,6 @@ "use strict"; | ||
} | ||
/** | ||
* Rotates the image data counter-clockwise by the specified angle. | ||
* TODO: convert this to clockwise rotation | ||
*/ | ||
static rotate(srcImageData, angle) { | ||
@@ -216,0 +220,0 @@ const dstImageData = Object.assign({}, srcImageData); |
@@ -28,4 +28,4 @@ import * as types from './types'; | ||
static from(bufferOrImageData: types.BufferLike | IAnnotatedImageData): Image; | ||
protected static _fromBuffer(buffer: types.BufferLike, metadata?: object): Image; | ||
protected static _fromBuffer(buffer: types.BufferLike, metadata?: Partial<types.IMetadata>): Image; | ||
protected static _fromImageData(imageData: IAnnotatedImageData): Image; | ||
} |
@@ -159,3 +159,3 @@ "use strict"; | ||
let buffer = bufferOrImageData; | ||
let exif = undefined; // tslint:disable-line | ||
let exif; | ||
const type = fileType(buffer) || { mime: 'unknown' }; | ||
@@ -162,0 +162,0 @@ switch (type.mime) { |
@@ -133,2 +133,4 @@ "use strict"; | ||
let image = yield imagePromise; | ||
// Make sure the image is rotated according to EXIF | ||
image = image.rotate(); | ||
image = yield this._applyResize(image); | ||
@@ -135,0 +137,0 @@ image = yield this._applyGreyscale(image); |
/// <reference types="node" /> | ||
import { INormalizedMetadata } from '@eris/exif'; | ||
export declare type MapPixelFn = (pixel: IPixel) => number[]; | ||
@@ -83,3 +84,3 @@ export interface IFormatOptions { | ||
aspectRatio: number; | ||
exif?: object; | ||
exif?: INormalizedMetadata; | ||
} | ||
@@ -86,0 +87,0 @@ export interface ISharpness { |
@@ -9,5 +9,8 @@ import {BufferLike, IMetadata, ImageResizeMethod} from './types' | ||
private readonly _image: Promise<IAnnotatedImageData> | ||
private readonly _metadata: object | undefined | ||
private readonly _metadata: Partial<IMetadata> | undefined | ||
public constructor(image: Promise<IAnnotatedImageData> | IAnnotatedImageData, metadata?: object) { | ||
public constructor( | ||
image: Promise<IAnnotatedImageData> | IAnnotatedImageData, | ||
metadata?: Partial<IMetadata>, | ||
) { | ||
super() | ||
@@ -18,2 +21,29 @@ this._image = Promise.resolve(image) | ||
private _applyEXIFOrientation(image: IAnnotatedImageData): IAnnotatedImageData { | ||
const exif = this._metadata && this._metadata.exif | ||
if (!exif || !exif._raw.Orientation) { | ||
return image | ||
} | ||
/** @see https://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/EXIF.html */ | ||
switch (exif._raw.Orientation) { | ||
case 1: | ||
// Do nothing | ||
break | ||
case 3: | ||
image = ImageData.rotate(image, 180) | ||
break | ||
case 6: | ||
image = ImageData.rotate(image, 270) // our rotate is CCW so 360 - 90 | ||
break | ||
case 8: | ||
image = ImageData.rotate(image, 90) // our rotate is CCW so 360 - 270 | ||
break | ||
default: | ||
throw new Error(`Unable to handle orientation ${exif._raw.Orientation}`) | ||
} | ||
return image | ||
} | ||
private _applyResize(image: IAnnotatedImageData): IAnnotatedImageData { | ||
@@ -51,2 +81,3 @@ if (!this._output.resize) { | ||
let image = await imagePromise | ||
image = await this._applyEXIFOrientation(image) | ||
image = await this._applyGreyscale(image) | ||
@@ -82,3 +113,3 @@ image = await this._applyResize(image) | ||
protected static _fromBuffer(buffer: BufferLike, metadata?: object): Image { | ||
protected static _fromBuffer(buffer: BufferLike, metadata?: Partial<IMetadata>): Image { | ||
return new BrowserImage(ImageData.from(buffer), metadata) | ||
@@ -85,0 +116,0 @@ } |
@@ -329,2 +329,6 @@ import { | ||
/** | ||
* Rotates the image data counter-clockwise by the specified angle. | ||
* TODO: convert this to clockwise rotation | ||
*/ | ||
public static rotate(srcImageData: IAnnotatedImageData, angle: number): IAnnotatedImageData { | ||
@@ -331,0 +335,0 @@ const dstImageData = {...srcImageData} |
@@ -7,3 +7,3 @@ import * as types from './types' | ||
import {sharpness as computeSharpness} from './analyses/sharpness' | ||
import {parse as parseEXIF, TIFFDecoder} from '@eris/exif' | ||
import {parse as parseEXIF, TIFFDecoder, INormalizedMetadata} from '@eris/exif' | ||
import {tone} from './transforms/tone' | ||
@@ -202,3 +202,3 @@ import {gaussianBlur} from './transforms/blur' | ||
let buffer = bufferOrImageData as Buffer | ||
let exif = undefined // tslint:disable-line | ||
let exif: INormalizedMetadata | undefined | ||
@@ -218,3 +218,6 @@ const type = fileType(buffer) || {mime: 'unknown'} | ||
protected static _fromBuffer(buffer: types.BufferLike, metadata?: object): Image { | ||
protected static _fromBuffer( | ||
buffer: types.BufferLike, | ||
metadata?: Partial<types.IMetadata>, | ||
): Image { | ||
throw new Error('unimplemented') | ||
@@ -221,0 +224,0 @@ } |
@@ -138,2 +138,6 @@ import * as sharp from 'sharp' | ||
let image = await imagePromise | ||
// Make sure the image is rotated according to EXIF | ||
image = image.rotate() | ||
image = await this._applyResize(image) | ||
@@ -140,0 +144,0 @@ image = await this._applyGreyscale(image) |
@@ -0,1 +1,3 @@ | ||
import {INormalizedMetadata} from '@eris/exif' | ||
export type MapPixelFn = (pixel: IPixel) => number[] | ||
@@ -96,3 +98,3 @@ | ||
aspectRatio: number | ||
exif?: object | ||
exif?: INormalizedMetadata | ||
} | ||
@@ -99,0 +101,0 @@ |
{ | ||
"name": "@eris/image", | ||
"version": "0.1.1-alpha.1", | ||
"version": "0.1.1-alpha.2", | ||
"description": "Collection of image manipulation libraries for node and the browser.", | ||
@@ -38,3 +38,3 @@ "main": "./dist/node-index.js", | ||
"dependencies": { | ||
"@eris/exif": "0.1.1-alpha.1", | ||
"@eris/exif": "0.1.1-alpha.2", | ||
"buffer": "^5.2.0", | ||
@@ -71,3 +71,3 @@ "file-type": "^7.0.1", | ||
}, | ||
"gitHead": "75848846ae0c982639ebe5670595cf36b43d9ce8" | ||
"gitHead": "3df1953422fd6152121a1846a1954735f78c3102" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1529227
12790
+ Added@eris/exif@0.1.1-alpha.2(transitive)
- Removed@eris/exif@0.1.1-alpha.1(transitive)
Updated@eris/exif@0.1.1-alpha.2