This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const rp = require('request-promise'); | |
const Jimp = require("jimp"); | |
(async () => { | |
const imageUrl = 'https://pbs.twimg.com/media/DWr05hUXcAA9s8n.jpg'; | |
const detectResult = await detectImage(imageUrl); | |
addMustache(imageUrl, detectResult, 'jav_rau.jpg'); | |
})(); | |
async function addMustache(url, detectResult, output) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const rp = require('request-promise'); | |
const Jimp = require("jimp"); | |
(async () => { | |
const imageUrl = 'https://pbs.twimg.com/media/DWr05hUXcAA9s8n.jpg'; | |
const detectResult = await detectImage(imageUrl); | |
addMustache(imageUrl, detectResult, 'jav_rau.jpg'); | |
})(); | |
async function addMustache(url, detectResult, output) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function addMustache(url, output) { | |
let source = await Jimp.read(url); | |
// Lấy chiều cao, rộng của ảnh | |
const { height, width } = source.bitmap; | |
const mustache = await Jimp.read('mustache.png'); | |
// Thu nhỏ bộ râu lại | |
mustache.resize(width, Jimp.AUTO); | |
return source.composite(mustache, 0, 0).write(output); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Jimp = require("jimp"); | |
async function addMustache(url, output) { | |
let source = await Jimp.read(url); // Đọc ảnh từ URL | |
const mustache = await Jimp.read('mustache.png'); // Đọc file râu | |
// Gắn file râu vào vị trí x=0, y=0, lưu ra output | |
return source.composite(mustache, 0, 0).write(output); | |
} | |
(async () => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"faceId": "2f3e1309-6e6f-4c2c-92a0-c68d898ba571", | |
"faceRectangle": { // Tọa độ khuôn mặt | |
"top": 109, | |
"left": 209, | |
"width": 109, | |
"height": 109 | |
}, | |
"faceLandmarks": { // Đặc điểm nhận dạng |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const rp = require('request-promise'); | |
async function detectImage(source) { | |
const subscriptionKey = "[thay bằng key của bạn]"; | |
const uri = "https://westcentralus.api.cognitive.microsoft.com/face/v1.0/detect"; | |
const options = { | |
uri, | |
qs: { | |
returnFaceId: true, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm init | |
npm install --save-dev request request-promise jimp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test('Install app', async() => { | |
expect.assertions(1); | |
// Tìm và click vào link | |
const appDownloadLink = await page.$x('//*[@id="topActionDownload"]'); | |
await appDownloadLink[0].click(); | |
await page.waitForNavigation(); | |
// Tìm element trên menu, lấy innerText của element đó | |
const breadCrumbHandle = await page.$x('/html/body/header/footer/div[2]/div[1]/ul/li[2]/span'); | |
const text = await page.evaluate(element => element.innerText, breadCrumbHandle[0]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test('Search sexy underwear', async() => { | |
expect.assertions(1); | |
// Tìm khung search, gõ sexy underwear và bấm enter | |
const searchBox = await page.$('#q'); | |
await searchBox.type('sexy underwear'); | |
await searchBox.press('Enter'); | |
// Chờ trang load xong, tìm các phần tử item và đếm nếu đủ 40 | |
await page.waitForNavigation(); | |
const products = await page.$$('div[data-qa-locator=product-item]'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let puppeteer = require('puppeteer'); | |
let browser = null; | |
let page = null; | |
describe('Lazada test', () => { | |
// Code này được chạy khi bắt đầu chạy unit test | |
beforeAll(async() => { | |
browser = await puppeteer.launch(); | |
page = await browser.newPage(); |