mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
feat(merge-img): new type definition v2.1 (#43124)
- definition type file - tests Used in BacktopJS tool: https://github.com/preco21/merge-img#readme Depends on: microsoft/types-publisher#754 Thanks!
This commit is contained in:
parent
12712d99e6
commit
851156006a
88
types/merge-img/index.d.ts
vendored
Normal file
88
types/merge-img/index.d.ts
vendored
Normal file
@ -0,0 +1,88 @@
|
||||
// Type definitions for merge-img 2.1
|
||||
// Project: https://github.com/preco21/merge-img#readme
|
||||
// Definitions by: Piotr Błażejewicz (Peter Blazejewicz) <https://github.com/peterblazejewicz>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
import Jimp = require('jimp');
|
||||
|
||||
/**
|
||||
* Merges given images into a single image in right order.
|
||||
* This will be helpful in a situation when you have to generate a preview of multiple images into a single image.
|
||||
* This module is based on Jimp for image processing.
|
||||
*/
|
||||
export default function mergeImg(
|
||||
images: Array<string | ImageDescriptor | Buffer | Jimp>,
|
||||
options?: Options,
|
||||
): Promise<Jimp>;
|
||||
|
||||
export interface ImageDescriptor {
|
||||
/**
|
||||
* A single image source to concat
|
||||
*/
|
||||
src: string | Buffer;
|
||||
/**
|
||||
* x offset to affect this image
|
||||
* @default 0
|
||||
*/
|
||||
offsetX?: number;
|
||||
/**
|
||||
* y offset to affect this image
|
||||
* @default 0
|
||||
*/
|
||||
offsetY?: number;
|
||||
}
|
||||
|
||||
export interface Options {
|
||||
/**
|
||||
* Direction of the merged image. If this value is true, the images will be merged vertically (column).
|
||||
* Otherwise, the images will be merged horizontally (row)
|
||||
* @default false
|
||||
*/
|
||||
direction?: boolean;
|
||||
/**
|
||||
* Default background color represented by RGBA hex value.
|
||||
* @default 0x00000000
|
||||
*/
|
||||
color?: number;
|
||||
/**
|
||||
* Aligning of given images. If the images are not all the same size, images will be sorted to largest image
|
||||
* @default 'start'
|
||||
*/
|
||||
align?: 'start' | 'center' | 'end';
|
||||
/**
|
||||
* Offset in pixels between each image
|
||||
* @default 0
|
||||
*/
|
||||
offset?: number;
|
||||
/**
|
||||
* Margin of the result image.
|
||||
* If `number` or `string` is passed, it will be considered as standard
|
||||
* css shorthand properties (e.g. '40 40 0 10')
|
||||
*/
|
||||
margin?: number | string | MarginOptions;
|
||||
}
|
||||
|
||||
export interface MarginOptions {
|
||||
/**
|
||||
* Margin on top side of result image
|
||||
* @default 0
|
||||
*/
|
||||
top?: number;
|
||||
/**
|
||||
* Margin on right side of result image
|
||||
* @default 0
|
||||
*/
|
||||
right?: number;
|
||||
/**
|
||||
* Margin on bottom side of result image
|
||||
* @default 0
|
||||
*/
|
||||
bottom?: number;
|
||||
/**
|
||||
* Margin on left side of result image
|
||||
* @default 0
|
||||
*/
|
||||
left?: number;
|
||||
}
|
||||
45
types/merge-img/merge-img-tests.ts
Normal file
45
types/merge-img/merge-img-tests.ts
Normal file
@ -0,0 +1,45 @@
|
||||
import mergeImg from 'merge-img';
|
||||
import { resolve } from 'path';
|
||||
const fixturePath = resolve(__dirname, 'fixtures');
|
||||
|
||||
mergeImg(['image-1.png', 'image-2.jpg']).then(img => {
|
||||
// Save image as file
|
||||
img.write('out.png', () => console.log('done'));
|
||||
});
|
||||
|
||||
mergeImg([
|
||||
{
|
||||
src: `${fixturePath}/example.png`,
|
||||
offsetX: 5,
|
||||
},
|
||||
{
|
||||
src: `${fixturePath}/example.png`,
|
||||
offsetX: 10,
|
||||
},
|
||||
]);
|
||||
|
||||
mergeImg([`${fixturePath}/example.png`, `${fixturePath}/example.png`], {
|
||||
direction: true,
|
||||
color: 0xffffffff,
|
||||
align: 'center',
|
||||
offset: 10,
|
||||
});
|
||||
mergeImg([
|
||||
{
|
||||
src: `${fixturePath}/example.png`,
|
||||
offsetY: 20,
|
||||
},
|
||||
{
|
||||
src: `${fixturePath}/example.png`,
|
||||
offsetX: 100,
|
||||
offsetY: 150,
|
||||
},
|
||||
]);
|
||||
mergeImg([`${fixturePath}/example.png`, `${fixturePath}/example.png`], {
|
||||
margin: {
|
||||
top: 40,
|
||||
right: 40,
|
||||
bottom: 0,
|
||||
left: 10,
|
||||
},
|
||||
});
|
||||
6
types/merge-img/package.json
Normal file
6
types/merge-img/package.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"jimp": "^0.9.5"
|
||||
}
|
||||
}
|
||||
24
types/merge-img/tsconfig.json
Normal file
24
types/merge-img/tsconfig.json
Normal file
@ -0,0 +1,24 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"esModuleInterop": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"merge-img-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/merge-img/tslint.json
Normal file
1
types/merge-img/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user