feat(aklive2d): add protrait images and live2d
This commit is contained in:
@@ -3,12 +3,12 @@ import path from "path";
|
||||
|
||||
export default class AlphaComposite {
|
||||
|
||||
async process(filename, extractedDir) {
|
||||
async process(filename, maskFilename, 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`))
|
||||
const mask = await sharp(path.join(extractedDir, maskFilename))
|
||||
.extractChannel("blue")
|
||||
.resize(imageMeta.width, imageMeta.height)
|
||||
.toBuffer();
|
||||
@@ -16,7 +16,16 @@ export default class AlphaComposite {
|
||||
return sharp(imageBuffer)
|
||||
.joinChannel(mask)
|
||||
.toBuffer()
|
||||
}
|
||||
|
||||
async crop(buffer, rect) {
|
||||
const left = rect.y
|
||||
const top = rect.x
|
||||
const width = rect.h
|
||||
const height = rect.w
|
||||
const rotate = rect.rotate === 0 ? -90 : 0
|
||||
const newImage = await sharp(buffer).rotate(90).extract({ left: left, top: top, width: width, height: height }).resize(width, height).extract({ left: 0, top: 0, width: width, height: height }).toBuffer()
|
||||
return await sharp(newImage).rotate(rotate).toBuffer()
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user