@twaves/node-image-concat
v0.0.3
Published
Node multiple images concat
Downloads
9
Maintainers
Readme
Install
$ npm install @twaves/node-image-concat --save
Usage
const ImagesConcat = require("@twaves/node-image-concat");
const base64Image = `iVBORw0KGgoAAAANSUhEUgAAAOAAAABgCAYAAAAEnX45AAAAAXNSR0IArs4c6QAAAERlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAA6ABAAMAAAABAAEAAKACAAQAAAABAAAA4KADAAQAAAABAAAAYAAAAAATv5SmAAAKtklEQVR4Ae2dC3RUxRnHv80TSMgmmIQQHlmEPAgGKjUILcGKWqlHTxWk2Fi1nLbSirT04amtLRVOK6e2yKmPPqxK6QOrxbQnWu2R2iq0NpICBWpAKCQG5JGEEJKQzYY8Ot+c3Mvu9d6dzbKzC+5/OGRnvvnuN7u/u//M3Jm5Ny6v1ztASCAAAjEhkBCTVtEoCICAJAAB4osAAjEkAAHGED6aBgEIEN8BEIghAQgwhvDRNAhAgPgOgEAMCUCAMYSPpkEAAsR3AARiSAACjCF8NA0CSUNFUNt5iDa21NDW9v3U4Gum3oH+oYaAPwh8oAgkuRLIk5pDFRlFVJk9i8rTLw3587mGshXtqw0baX3T1pCDwxEE4pHAktwKWuepDOmjhyzABe88Rn87XRdSUDiBQLwTmOcupari5UoMIV0Dcs8H8SlZwgEETAKsF9aNKikFyNd8GHaqMKIeBN5PgHXD+gmWlALkCRckEACB8Aio9KMUIM92IoEACIRHQKUfpQB5qQEJBEAgPAIq/SgFiHW+8MDjKBBgAir9KAUIjCAAAvoIQID62CIyCCgJQIBKRHAAAX0EIEB9bBEZBJQEIEAlIjiAgD4CEKA+togMAkoCEKASERxAQB8BCFAfW0QGASUBCFCJCA4goI8ABKiPLSKDgJIABKhEBAcQ0EcAAtTHFpFBQEkAAlQiggMI6CMAAepji8ggoCQAASoRwQEE9BGAAPWxRWQQUBKAAJWI4AAC+ghAgPrYxjxyWmJqzN8D3kBwAhBgcD4Rq/38mI/Rlsu/S0vy5lK0hFF92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LHN4lGALDzekG1NA2IF4kTPaat5SGVf//s3dA8pAJxjTgAC1HQK+HkvwRKv+RXUrAjmElYdX1sa9xl2+910GyxYfXcT1bT/T7rwljmk6BFweb3ewNVgS9uZ275ksaAIAiAwFAJtM3/m6I67IRzRoAIE9BOAAPUzRgsg4EgAAnREgwoQ0E8AAtTPGC2AgCMBCNARDSpAQD8BCFA/Y7QAAo4EIEBHNKgAAf0EIED9jNECCDgSgAAd0aACBPQTgAD1M0YLIOBIAAJ0RIMKENBPAALUzxgtgIAjAQjQEQ0qQEA/AQhQP2O0AAKOBCBARzSoAAH9BCBA/YzRAgg4EoAAHdGgAgT0E4AA9TNGCyDgSEApwCSX0sUxOCpAIN4JqPSjVJcnNSfeGeLzg0DYBFT6UQqwIqMo7MZxIAjEOwGVfpQCrMx2/oON8Q4Xnx8EVARU+lEKsDz9UlqSW6FqB/UgAAIWAqwb1k+wpBQgH7zOU0nz3KXB4qAOBEDAjwDrhXWjSiEJkINUFS9HT6iiiXoQEAS452O9hJKUT8a2BqntPEQbW2poa/t+avA1Ex5lbiWEcrwR4KUGnu3kCRe+5lMNO/35DFmA/gcjDwIgcH4EQh6Cnl8zOBoEQMCOAARoRwU2EIgSAQgwSqDRDAjYEYAA7ajABgJRIgABRgk0mgEBOwL/B8mnlsXItcKTAAAAAElFTkSuQmCC`;
const base64Data = await ImagesConcat([base64Image, base64Image]);
// 将Base64字符串转换为缓冲区
const bitmap = Buffer.from(
base64Data?.replace("data:image/jpeg;base64,", ""),
"base64"
);
// 写入文件到指定路径
fs.writeFileSync(path.resolve("/Users", `test.jpg`), bitmap);
API
ImagesConcat(images[, options])
images
Array of (Base64 Images) - List of images to concat.options
Object (optional)direction
Boolean - Direction of the merged image. If this value istrue
, the images will be merged vertically (column). Otherwise, the images will be merged horizontally (row). Default isfalse
.color
Number | String (hex) - Default background color represented by RGBA hex value. Default is0x00000000
.align
String - Aligning of given images. If the images are not all the same size, images will be sorted to largest image. Possible values arestart
,center
andend
. Default isstart
.offset
Number - Offset in pixels between each image. Default is0
.margin
(Number | String | Object) - Margin of the result image. IfNumber
orString
is passed, it will be considered as standard css shorthand properties (e.g. '40 40 0 10'). AnObject
entry can have following options:top
Number (optional) - Margin on top side of result image. Default is0
.right
Number (optional) - Margin on right side of result image. Default is0
.bottom
Number (optional) - Margin on bottom side of result image. Default is0
.left
Number (optional) - Margin on left side of result image. Default is0
.
dWidth
Number - Set Image Width. Default is0
.dHeight
Number - Set Image Height. Default is0
.
Returns a Promise
that resolves to the merged Base64 Image.