feat(node): re-write using node

This commit is contained in:
Haoyu Xu
2023-01-16 14:06:14 -05:00
parent 4b834fe0ff
commit 6d54eb068c
95 changed files with 1341 additions and 2486 deletions

31
lib/alpha_composite.js Normal file
View File

@@ -0,0 +1,31 @@
import sharp from "sharp";
import path from "path";
export default class AlphaComposite {
#config
#operatorName
#operatorSourceFolder
constructor(config, operatorName, rootDir) {
this.#config = config
this.#operatorName = operatorName
this.#operatorSourceFolder = path.join(rootDir, this.#config.folder.operator, this.#operatorName)
}
async process(filename, extractedDir) {
const image = sharp(path.join(extractedDir, filename))
.removeAlpha()
const imageMeta = await image.metadata()
const imageBuffer = await image.toBuffer()
const mask = await sharp(path.join(extractedDir, `${path.parse(filename).name}[alpha].png`))
.extractChannel("blue")
.resize(imageMeta.width, imageMeta.height)
.toBuffer();
return sharp(imageBuffer)
.joinChannel(mask)
.toBuffer()
}
}