-
Notifications
You must be signed in to change notification settings - Fork 26
/
face_detect_download.js
52 lines (46 loc) · 1.6 KB
/
face_detect_download.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Run this file as:
//
// env TRANSLOADIT_KEY=xxx TRANSLOADIT_SECRET=yyy node examples/face_detect_download.js ./fixtures/berkley.jpg
//
// This example will take an image and find a face and crop out the face.
// Then it will download the result as a file in the current directory
// See https://transloadit.com/demos/artificial-intelligence/detect-faces-in-images/
//
// You'll likely just want to `require('transloadit')`, but we're requiring the local
// variant here for easier testing:
const TransloaditClient = require('../src/TransloaditClient')
const got = require('got')
const { createWriteStream } = require('fs')
const transloadit = new TransloaditClient({
authKey : process.env.TRANSLOADIT_KEY,
authSecret: process.env.TRANSLOADIT_SECRET,
})
const filePath = process.argv[2]
transloadit.addFile('image', filePath);
(async () => {
try {
const opts = {
waitForCompletion: true,
params : {
steps: {
facesDetected: {
use : ':original',
robot : '/image/facedetect',
crop : true,
crop_padding: '10%',
faces : 'max-confidence',
format : 'preserve',
},
},
},
}
const status = await transloadit.createAssembly(opts)
// Now save the file
const outPath = './output-face.jpg'
const stream = createWriteStream(outPath)
await got.stream(status.results.facesDetected[0].url).pipe(stream)
console.log('Your cropped face has been saved to', outPath)
} catch (err) {
console.error('createAssembly failed', err)
}
})()