imagetools-core
Advanced tools
Comparing version 6.0.1 to 6.0.2
@@ -0,1 +1,3 @@ | ||
import 'sharp'; | ||
const METADATA = Symbol('image metadata'); | ||
@@ -10,2 +12,56 @@ function setMetadata(image, key, value) { | ||
const kernelValues = ['nearest', 'cubic', 'mitchell', 'lanczos2', 'lanczos3']; | ||
const getKernel = ({ kernel }, image) => { | ||
if (kernel && kernelValues.includes(kernel)) { | ||
image[METADATA].kernel = kernel; | ||
return kernel; | ||
} | ||
}; | ||
const positionValues = [ | ||
'top', | ||
'right top', | ||
'right', | ||
'right bottom', | ||
'bottom', | ||
'left bottom', | ||
'left', | ||
'left top', | ||
'north', | ||
'northeast', | ||
'east', | ||
'southeast', | ||
'south', | ||
'southwest', | ||
'west', | ||
'northwest', | ||
'center', | ||
'centre', | ||
'entropy', | ||
'attention' | ||
]; | ||
const positionShorthands = [ | ||
'top', | ||
'right top', | ||
'right', | ||
'right bottom', | ||
'bottom', | ||
'left bottom', | ||
'left', | ||
'left top' | ||
]; | ||
const getPosition = (config, image) => { | ||
let position = undefined; | ||
if (config.position && positionValues.includes(config.position)) { | ||
position = config.position; | ||
} | ||
else { | ||
position = Object.keys(config).find((k) => positionShorthands.includes(k) && config[k] === ''); | ||
} | ||
if (!position) | ||
return; | ||
image[METADATA].position = position; | ||
return position; | ||
}; | ||
const getBackground = ({ background }, image) => { | ||
@@ -151,10 +207,2 @@ if (typeof background !== 'string' || !background.length) | ||
const kernelValues = ['nearest', 'cubic', 'mitchell', 'lanczos2', 'lanczos3']; | ||
const getKernel = ({ kernel }, image) => { | ||
if (kernel && kernelValues.includes(kernel)) { | ||
image[METADATA].kernel = kernel; | ||
return kernel; | ||
} | ||
}; | ||
const median = (config) => { | ||
@@ -179,48 +227,2 @@ const median = config.median ? parseInt(config.median) : undefined; | ||
const positionValues = [ | ||
'top', | ||
'right top', | ||
'right', | ||
'right bottom', | ||
'bottom', | ||
'left bottom', | ||
'left', | ||
'left top', | ||
'north', | ||
'northeast', | ||
'east', | ||
'southeast', | ||
'south', | ||
'southwest', | ||
'west', | ||
'northwest', | ||
'center', | ||
'centre', | ||
'entropy', | ||
'attention' | ||
]; | ||
const positionShorthands = [ | ||
'top', | ||
'right top', | ||
'right', | ||
'right bottom', | ||
'bottom', | ||
'left bottom', | ||
'left', | ||
'left top' | ||
]; | ||
const getPosition = (config, image) => { | ||
let position = undefined; | ||
if (config.position && positionValues.includes(config.position)) { | ||
position = config.position; | ||
} | ||
else { | ||
position = Object.keys(config).find((k) => positionShorthands.includes(k) && config[k] === ''); | ||
} | ||
if (!position) | ||
return; | ||
image[METADATA].position = position; | ||
return position; | ||
}; | ||
/** | ||
@@ -227,0 +229,0 @@ * This function parses a user provided aspect-ratio string into a float. |
import { Sharp } from 'sharp'; | ||
import { ImageMetadata } from '../types'; | ||
import { ImageMetadata } from '../types.js'; | ||
export declare const METADATA: unique symbol; | ||
@@ -4,0 +4,0 @@ declare module 'sharp' { |
import { Metadata, Sharp } from 'sharp'; | ||
import { kernelValues } from './transforms/kernel'; | ||
import { positionValues } from './transforms/position'; | ||
import { kernelValues } from './transforms/kernel.js'; | ||
import { positionValues } from './transforms/position.js'; | ||
export interface ProcessedImageMetadata extends ImageMetadata { | ||
@@ -5,0 +5,0 @@ src: string; |
{ | ||
"name": "imagetools-core", | ||
"version": "6.0.1", | ||
"version": "6.0.2", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "types": "dist/index.d.ts", |
Sorry, the diff of this file is not supported yet
77490
829