Skip to content

Instantly share code, notes, and snippets.

@conanak99
Last active April 14, 2018 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save conanak99/59c8221937721ffb9a039972d7c1f335 to your computer and use it in GitHub Desktop.
Save conanak99/59c8221937721ffb9a039972d7c1f335 to your computer and use it in GitHub Desktop.
(async () => {
const imageUrl = 'http://storage.vpopfan.com/sontungmtp.jpg';
const detectResult = await detectImage(imageUrl);
addFlower(imageUrl, detectResult, 'jav_flower.jpg');
})();
async function addFlower(url, detectResult, output) {
// Tính toán vị trí và khuôn mặt
const face = detectResult[0]; // Hình chỉ nhận được 1 khuôn mặt
const { top, left, width, height } = face.faceRectangle;
// Resize hoa
let source = await Jimp.read(url);
const flower = await Jimp.read('flower.png');
flower.resize(width * 1.3, Jimp.AUTO);
// Tìm địa điểm đặt vòng hoa
const x = left + width/2;
// Hoa được đặt giữa trán
// Tìm tọa độ trán thông qua độ dài mũi
// Trán sẽ cách đỉnh mủi 1.5 lần độ dài mũi
const landmarks = face.faceLandmarks;
const noseRootLeft = landmarks['noseRootLeft'];
const noseHeight = landmarks['noseTip'].y - noseRootLeft.y;
const y = noseRootLeft.y - noseHeight*1.5;
addImageCenter(source, flower, x, y);
return source.write(output);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment