Jay Taylor's notes

back to listing index

How I Ruined Office Productivity With a Face-Replacing Slack Bot · zikes.me blog

[web search]
Original source (blog.zikes.me)
Tags: golang go irc image-processing slack facial-recognition slackbot blog.zikes.me
Clipped on: 2017-02-19

code and games
© Jason Hutchinson
Built with Hugo and Hyde-Y.

How I Ruined Office Productivity With a Face-Replacing Slack Bot

(Without Really Knowing What I Was Doing)

February 16, 2017 · Read in about 8 min · (1594 Words)

Meet Chris.

Image (Asset 1/27) alt=

NICE

The first iteration used Slack uploads, but being on a free Slack tier meant this was not ideal. I changed that to save the output locally onto my server, and then link that in Slack. Since Slack will auto-expand most image links, this wound up being an equivalent user experience for most people without as much risk of me getting in trouble with the office bigwigs.

With easy access to the process, I was able to more easily experiment with the face replacer. I realized that if it didn’t find any faces at all, it would just echo the same image back. That’s no fun! So I threw this in after the loop:

if len(faces) == 0 {
  // Grab a specific face and resize it to 1/3 the width
  // of the base image
  face := imaging.Resize(
    chrisFaces[0],
    bounds.Dx()/3,
    0,
    imaging.Lanczos,
  )

  face_bounds := face.Bounds()

  draw.Draw(
    canvas,
    bounds,
    face,
    // I'll be honest, I was a couple beers in when I came up with this and I
    // have no idea how it works exactly, but it puts the face at the bottom of
    // the image, centered horizontally with the lower half of the face cut off
    bounds.Min.Add(image.Pt(
      -bounds.Max/2+face_bounds.Max.X/2,
      -bounds.Max.Y+int(float64(face_bounds.Max.Y)/1.9),
    )),
    draw.Over,
  )
}

Which gave me this:

Image (Asset 2/27) alt=