은승우

Update app.js

Showing 1 changed file with 17 additions and 8 deletions
......@@ -5,7 +5,7 @@ var request = require('request');
var https=require('https');
var http=require('http');
var mime=require('mime-types');
var png=require('png-js');
var fs = require("fs");
var httpsOptions = {
......@@ -89,6 +89,16 @@ async function handleEvent(event) {
await stream.on('data', (chunk) => {
console.log(typeof(chunk));
fs.writeFileSync("./photo/1.png",chunk);
var PNG = require('png-js');
var myimage = new PNG("./photo/1.png");
var width = myimage.width;
var height = myimage.height;
myimage.decode(function (pixels) {
//Pixels is a 1D array containing pixel data
var cheerio = require('cheerio');
var uriBase = 'https://koreacentral.api.cognitive.microsoft.com/vision/v2.1/ocr';
var options = {
......@@ -101,14 +111,11 @@ async function handleEvent(event) {
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': '979dc5d63344438fa4701c62feebb7dc'
},
body: fs.readFileSync("./photo/1.png")
body: myimage
};
app.get('/photo',(req,res)=>{
res.send(chunk+"png");
})
/*
request.post(options, function (error, response, body) {
var data=body;
var data=options.body;
console.log(data);
var text='';
while(data.indexOf('text\\')!=-1)
......@@ -140,7 +147,9 @@ async function handleEvent(event) {
}
client.replyMessage(event.replyToken,result).then(resolve).catch(reject);
});
});*/
});
});
......