Skip to content

Instantly share code, notes, and snippets.

View conanak99's full-sized avatar

Phạm Huy Hoàng conanak99

View GitHub Profile
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) {
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) {
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);
}
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 () => {
[
{
"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
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,
npm init
npm install --save-dev request request-promise jimp
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]);
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]');
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();