Giter Club home page Giter Club logo

facemorph's Introduction

facemorph

Create animated GIFs that morph faces to each other in Node.js.

I wanted a simple way to take a set of pictures we take periodically of our newborn son and watch as he changed over time. All the potential solutions I found to date required a GUI to identify facial landmarks and/or the morphing didn't work that well, so I decided to combine the separate pieces of each step to create a relatively good face morphing into a single library with a dead simple API.

Assumptions/Limitations

  • Each image in the created GIF must contain exactly one face. If no faces or more than one are detected, that picture is ignored in the output GIF.
  • A minimum of two images are required to be provided in createGif (see below).
  • Faces are detected using the model provided in face-api.js. Human faces work best, where animal faces might or might not work.
  • For best results, use images with white (or consistent) backgrounds.

Install

$ npm install facemorph

Simple Usage

API

import fs from 'fs'
import Facemorph from 'facemorph'

const facemorph = Facemorph()
const gifBuffer = await facemorph.createGif([
  '/path/to/img/with/face.png', // file system path of image
  rawImgBuffer, // Buffer of image data
  streamOfImg, // Readable stream containing raw image data
  // more images...
])
await fs.promises.writeFile(`my.gif`, gifBuffer)

CLI

$ node node_modules/facemorph/dist/tasks/createGif -i path/to/img1.jpg -i path/to/img2.png
Your new gif: /path/to/output/facemorph_#############.gif

API

constructor

import Facemorph from 'facemorph'

// `frames: number = 20` is the number of frames between each face morph in the GIF
const facemorph = Facemorph(/* frames */)

createGif

Create a GIF with morphed faces between all provided images.

// images: MorfImages[] - Array of at least 2 images that can be a string, Readable stream, or raw Buffer
// delayMs: number = 20 - The delay in milliseconds between each frame
// repeat: number = 0 - Whether to repeat the GIF animation or not. -1: no repeat, 0 repeat
await facemorph.createGif(images /*, delayMs, repeat */) // : Promise<Buffer>

createFrames

Create an array of Buffers that are images of all the frames to be used to create an animated GIF of morphed faces. This is used inside of createGif, but could be used as a standalone if you want to take all the frames and do what you'd like with them.

// images: MorfImages[] - Array of at least 2 images that can be a string, Readable stream, or raw Buffer
await facemorph.createFrames(images) // : Promise<Buffer[][]>

setFrames

Reset the number of frames between each face morph.

facemorph.setFrames(10) // : number

facemorph's People

Contributors

whatl3y avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.