From 851156006a7c8376c860a4e143876eecbddcca6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20B=C5=82a=C5=BCejewicz=20=28Peter=20Blazejewicz=29?= Date: Fri, 20 Mar 2020 17:03:07 +0100 Subject: [PATCH] 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! --- types/merge-img/index.d.ts | 88 ++++++++++++++++++++++++++++++ types/merge-img/merge-img-tests.ts | 45 +++++++++++++++ types/merge-img/package.json | 6 ++ types/merge-img/tsconfig.json | 24 ++++++++ types/merge-img/tslint.json | 1 + 5 files changed, 164 insertions(+) create mode 100644 types/merge-img/index.d.ts create mode 100644 types/merge-img/merge-img-tests.ts create mode 100644 types/merge-img/package.json create mode 100644 types/merge-img/tsconfig.json create mode 100644 types/merge-img/tslint.json diff --git a/types/merge-img/index.d.ts b/types/merge-img/index.d.ts new file mode 100644 index 0000000000..ef8e97679b --- /dev/null +++ b/types/merge-img/index.d.ts @@ -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) +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +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, + options?: Options, +): Promise; + +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; +} diff --git a/types/merge-img/merge-img-tests.ts b/types/merge-img/merge-img-tests.ts new file mode 100644 index 0000000000..c11e350edb --- /dev/null +++ b/types/merge-img/merge-img-tests.ts @@ -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, + }, +}); diff --git a/types/merge-img/package.json b/types/merge-img/package.json new file mode 100644 index 0000000000..d6bb7185b6 --- /dev/null +++ b/types/merge-img/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "dependencies": { + "jimp": "^0.9.5" + } +} diff --git a/types/merge-img/tsconfig.json b/types/merge-img/tsconfig.json new file mode 100644 index 0000000000..99be50ae80 --- /dev/null +++ b/types/merge-img/tsconfig.json @@ -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" + ] +} diff --git a/types/merge-img/tslint.json b/types/merge-img/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/merge-img/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }