-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
28 lines (28 loc) · 971 Bytes
/
index.js
File metadata and controls
28 lines (28 loc) · 971 Bytes
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
const Canvas = require('canvas');
const fs = require('fs');
const canvas = new Canvas(256, 256);
const ctx = canvas.getContext('2d');
const Image = Canvas.Image;
const axios = require('axios');
axios({
method: 'get',
url: 'http://www.google.cn/maps/vt?lyrs=m@189&gl=cn&x=12&y=6&z=4',
responseType: 'arraybuffer'
// responseType: 'stream'
}).then((response) => {
const img = new Image();
img.src = response.data;
// img.src = new ArrayBuffer([response.data]);
ctx.drawImage(img, 0, 0, img.width, img.height);
canvas.createPNGStream().pipe(fs.createWriteStream(__dirname + '/images/res.png'));
}).catch(error => {
console.log(error)
})
// fs.readFile(__dirname + '/images/2.png', function(err, squid){
// if (err) throw err;
// console.log(squid)
// const img = new Image();
// img.src = squid;
// ctx.drawImage(img, 0, 0, img.width, img.height);
// canvas.createPNGStream().pipe(fs.createWriteStream(__dirname + '/images/res.png'));
// });