@eris/image
Advanced tools
Comparing version 0.1.1-alpha.4 to 0.1.1-alpha.5
@@ -79,2 +79,3 @@ "use strict"; | ||
image = yield this._applyEdges(image); | ||
image = yield this._applyEffects(image); | ||
return image; | ||
@@ -81,0 +82,0 @@ }); |
import { INoiseOptions } from '../types'; | ||
import { IAnnotatedImageData } from '../image-data'; | ||
export declare function noise(options: INoiseOptions): IAnnotatedImageData; | ||
export declare function noise(width: number, height: number, options?: INoiseOptions): IAnnotatedImageData; |
@@ -6,4 +6,4 @@ "use strict"; | ||
const alea_1 = require("../third-party/alea"); | ||
function noise(options) { | ||
const { width, height, seed = 'noise' } = options; | ||
function noise(width, height, options = {}) { | ||
const { seed = 'noise' } = options; | ||
const prng = alea_1.createPRNG(seed); | ||
@@ -10,0 +10,0 @@ const data = new Uint8Array(width * height); |
@@ -18,2 +18,3 @@ import * as types from './types'; | ||
edges(method?: types.EdgeMethod | types.IEdgeOptions): Image; | ||
effects(effects: types.IEffect[]): Image; | ||
analyze(options: types.IAnalysisOptions): Image; | ||
@@ -26,2 +27,3 @@ toAnalysis(): Promise<types.IAnalysis>; | ||
protected _applyEdges(image: IAnnotatedImageData): IAnnotatedImageData; | ||
protected _applyEffects(image: IAnnotatedImageData): IAnnotatedImageData; | ||
abstract toMetadata(): Promise<types.IMetadata>; | ||
@@ -28,0 +30,0 @@ abstract toImageData(): Promise<IAnnotatedImageData>; |
@@ -16,2 +16,3 @@ "use strict"; | ||
const opacity_1 = require("./transforms/opacity"); | ||
const noise_1 = require("./effects/noise"); | ||
/* tslint:disable-next-line */ | ||
@@ -32,2 +33,4 @@ const fileType = require('file-type'); | ||
this.resize(options.resize); | ||
if (options.layers) | ||
this.layers(options.layers); | ||
if (options.calibrate) | ||
@@ -43,2 +46,4 @@ this.calibrate(options.calibrate); | ||
this.edges(options.edges); | ||
if (options.effects) | ||
this.effects(options.effects); | ||
return this; | ||
@@ -97,2 +102,6 @@ } | ||
} | ||
effects(effects) { | ||
this._output.effects = effects; | ||
return this; | ||
} | ||
analyze(options) { | ||
@@ -171,2 +180,22 @@ this._analyze = options; | ||
} | ||
_applyEffects(image) { | ||
if (!this._output.effects) { | ||
return image; | ||
} | ||
let imageWithEffects = image; | ||
for (const effect of this._output.effects) { | ||
switch (effect.type) { | ||
case types.EffectType.Noise: | ||
const options = effect.options || {}; | ||
const opacityValue = options.opacity || 0.05; | ||
const noiseLayer = noise_1.noise(imageWithEffects.width, imageWithEffects.height, effect.options); | ||
const noiseMatched = image_data_1.ImageData.toColorspace(noiseLayer, imageWithEffects.colorspace); | ||
imageWithEffects = opacity_1.opacity(imageWithEffects, noiseMatched, opacityValue); | ||
break; | ||
default: | ||
throw new Error(`Unrecognized type: ${effect.type}`); | ||
} | ||
} | ||
return imageWithEffects; | ||
} | ||
toFile(path) { | ||
@@ -173,0 +202,0 @@ return this.toBuffer().then(buffer => fs_utils_1.writeFileAsync(path, buffer)); |
@@ -115,3 +115,4 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!this._output.edges && | ||
if (!this._output.effects && | ||
!this._output.edges && | ||
!this._output.layers && | ||
@@ -130,2 +131,3 @@ !this._output.tone && | ||
imageData = yield this._applyEdges(imageData); | ||
imageData = yield this._applyEffects(imageData); | ||
return SharpImage.from(imageData); | ||
@@ -132,0 +134,0 @@ }); |
@@ -24,6 +24,12 @@ /// <reference types="node" /> | ||
export interface INoiseOptions { | ||
width: number; | ||
height: number; | ||
seed?: string; | ||
opacity?: number; | ||
} | ||
export declare enum EffectType { | ||
Noise = "noise" | ||
} | ||
export declare type IEffect = { | ||
type: EffectType.Noise; | ||
options?: INoiseOptions; | ||
}; | ||
export interface IToneOptions { | ||
@@ -63,2 +69,3 @@ /** Affects the overall contrast in the image, typically a number between -0.5 and 2, reasonable range of -0.1 to 0.3 */ | ||
edges?: IEdgeOptions; | ||
effects?: IEffect[]; | ||
} | ||
@@ -65,0 +72,0 @@ export interface IAnalysisOptions { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var EffectType; | ||
(function (EffectType) { | ||
EffectType["Noise"] = "noise"; | ||
})(EffectType = exports.EffectType || (exports.EffectType = {})); | ||
var ImageFormat; | ||
@@ -4,0 +8,0 @@ (function (ImageFormat) { |
@@ -87,2 +87,3 @@ import {BufferLike, IMetadata, ImageResizeMethod} from './types' | ||
image = await this._applyEdges(image) | ||
image = await this._applyEffects(image) | ||
return image | ||
@@ -89,0 +90,0 @@ } |
@@ -5,4 +5,8 @@ import {INoiseOptions, Colorspace} from '../types' | ||
export function noise(options: INoiseOptions): IAnnotatedImageData { | ||
const {width, height, seed = 'noise'} = options | ||
export function noise( | ||
width: number, | ||
height: number, | ||
options: INoiseOptions = {}, | ||
): IAnnotatedImageData { | ||
const {seed = 'noise'} = options | ||
const prng = createPRNG(seed) | ||
@@ -9,0 +13,0 @@ |
@@ -14,2 +14,3 @@ import * as types from './types' | ||
import {opacity} from './transforms/opacity' | ||
import {noise} from './effects/noise' | ||
@@ -33,2 +34,3 @@ /* tslint:disable-next-line */ | ||
if (options.resize) this.resize(options.resize) | ||
if (options.layers) this.layers(options.layers) | ||
if (options.calibrate) this.calibrate(options.calibrate) | ||
@@ -39,2 +41,3 @@ if (options.tone) this.tone(options.tone) | ||
if (options.edges) this.edges(options.edges) | ||
if (options.effects) this.effects(options.effects) | ||
return this | ||
@@ -115,2 +118,7 @@ } | ||
public effects(effects: types.IEffect[]): Image { | ||
this._output.effects = effects | ||
return this | ||
} | ||
public analyze(options: types.IAnalysisOptions): Image { | ||
@@ -208,3 +216,25 @@ this._analyze = options | ||
} | ||
protected _applyEffects(image: IAnnotatedImageData): IAnnotatedImageData { | ||
if (!this._output.effects) { | ||
return image | ||
} | ||
let imageWithEffects = image | ||
for (const effect of this._output.effects) { | ||
switch (effect.type) { | ||
case types.EffectType.Noise: | ||
const options = effect.options || {} | ||
const opacityValue = options.opacity || 0.05 | ||
const noiseLayer = noise(imageWithEffects.width, imageWithEffects.height, effect.options) | ||
const noiseMatched = ImageData.toColorspace(noiseLayer, imageWithEffects.colorspace) | ||
imageWithEffects = opacity(imageWithEffects, noiseMatched, opacityValue) | ||
break | ||
default: | ||
throw new Error(`Unrecognized type: ${effect.type}`) | ||
} | ||
} | ||
return imageWithEffects | ||
} | ||
public abstract toMetadata(): Promise<types.IMetadata> | ||
@@ -211,0 +241,0 @@ |
@@ -119,2 +119,3 @@ import * as sharp from 'sharp' | ||
if ( | ||
!this._output.effects && | ||
!this._output.edges && | ||
@@ -136,2 +137,3 @@ !this._output.layers && | ||
imageData = await this._applyEdges(imageData) | ||
imageData = await this._applyEffects(imageData) | ||
return SharpImage.from(imageData) | ||
@@ -138,0 +140,0 @@ } |
@@ -28,7 +28,13 @@ import {INormalizedMetadata} from '@eris/exif' | ||
export interface INoiseOptions { | ||
width: number | ||
height: number | ||
seed?: string | ||
opacity?: number | ||
} | ||
export enum EffectType { | ||
Noise = 'noise', | ||
} | ||
// tslint:disable-next-line | ||
export type IEffect = {type: EffectType.Noise; options?: INoiseOptions} | ||
export interface IToneOptions { | ||
@@ -71,2 +77,3 @@ /** Affects the overall contrast in the image, typically a number between -0.5 and 2, reasonable range of -0.1 to 0.3 */ | ||
edges?: IEdgeOptions | ||
effects?: IEffect[] | ||
} | ||
@@ -73,0 +80,0 @@ |
{ | ||
"name": "@eris/image", | ||
"version": "0.1.1-alpha.4", | ||
"version": "0.1.1-alpha.5", | ||
"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.4", | ||
"@eris/exif": "0.1.1-alpha.5", | ||
"buffer": "^5.2.0", | ||
@@ -71,3 +71,3 @@ "file-type": "^7.0.1", | ||
}, | ||
"gitHead": "96a4a5db62be9fef1ec507d12b9d73e40d884229" | ||
"gitHead": "d7efeea841cd025988c4aa5273c449379cba3b89" | ||
} |
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
1572246
13308
+ Added@eris/exif@0.1.1-alpha.5(transitive)
- Removed@eris/exif@0.1.1-alpha.4(transitive)
Updated@eris/exif@0.1.1-alpha.5