UNPKG

@twaves/node-image-concat

Version:

Node multiple images concat

3 lines (2 loc) 1.43 kB
"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}function e(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}const r=t(require("jimp")).default,o=function(t={}){if(Number.isInteger(t))return{top:t,right:t,bottom:t,left:t};if("string"==typeof t){const[e,r=e,o=e,n=r]=t.split(" ");return{top:Number(e),right:Number(r),bottom:Number(o),left:Number(n)}}const{top:e=0,right:r=0,bottom:o=0,left:n=0}=t;return{top:e,right:r,bottom:o,left:n}};var n=function(t,{color:e=0,align:n="start",offset:i=0,isPng:a=!1,margin:s,dWidth:f=0,dHeight:u=0,xCount:m=3}={}){if(!Array.isArray(t))throw new TypeError("`images` must be an array that contains images");if(t.length<1)throw new Error("At least `images` must contain more than one image");return Promise.all(t.map((async t=>{const e=await new Buffer.from(t,"base64");return r.read(e).then((t=>({img:t.scaleToFit(f,u)})))}))).then((t=>{const n=t.reduce(((t,{img:e,offsetX:r=0,offsetY:o=0},n)=>(t.push({img:e,x:Number(n%m)*f+r+i,y:Math.floor(n/m)*u+o+i,offsetX:r,offsetY:o}),t)),[]),{top:l,right:c,bottom:g,left:h}=o(s),p=l+g,b=c+h,d=n.length,y=Math.min(m,d)*f+(m-1)*i,M=Math.ceil(d/m)*u+(Math.ceil(d/m)-1)*i,w=new r(y+b,M+p,e),N=n.map(((t,e)=>[e,t]));for(const[,{img:t,x:e,y:r}]of N)w.composite(t,e+h,r+l);return w.getBase64Async(a?r.MIME_PNG:r.MIME_JPEG)}))},i=e(n);module.exports=i; //# sourceMappingURL=index.min.js.map