Creating headshots for all employee photos made easy
A developer can easily create a workflow using the tweekit web application to crop the headshots for all HR employee photos from any format uploaded, making it easy to get the content you need, with no hassles from your employees.
Before starting, always include the
tweekit_bundle.js
-
Rest Version
-
Widget Version
rest_api_example.js
const fetch = require('node-fetch');
const fs = require('fs');
const headers = {
"apikey": "{Example Key}",
"apisecret": "{Example Secret}",
"Content-Type": "application/json;charset=UTF-8"
};
const baseUrl = 'https://www.tweekit.io/tweekit/api'
async function resize({ docID, width, height }) {
const format = 'png'
const fetchUrl = `${baseUrl}/image/${docID}`;
const options ={
headers ,
method: 'POST',
body: JSON.stringify({
height,
width,
fmt: format
})
};
const response = await fetch(fetchUrl,options);
response.body.pipe(fs.createWriteStream(`${Date.now()}-test.${format}`));
}
async function upload({ avatar, filename }) {
formData.append("name", filename);
formData.append("file", fs.createReadStream(avatar));
const fetchUrl = `${baseUrl}/image/upload`;
const response = await fetch(fetchUrl, opts);
const docID = response.headers.get('x-tweekit-docid')
return { docID, response }
}
function storeEmployeePhotosToDB(employeeObj) {
const { avatar, name, id } = employeeObj
const filename = `${id}_${name.replace("", "_").toLowerCase()}.png`
const { docID } = await upload({ avatar, filename })
resize({ docID, width: 300 , height: 300 })
}
async function main() {
const employeeList = await fetch('sample_employee_url'. {
method: 'GET'
})
employeeList.map((employee) => {
storeEmployeePhotosToDB(employee)
})
}