forked from peterbraden/node-opencv
-
Notifications
You must be signed in to change notification settings - Fork 1
/
async-resize.js
38 lines (31 loc) · 1006 Bytes
/
async-resize.js
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
29
30
31
32
33
34
35
36
37
38
var cv = require('../lib/opencv');
cv.readImage("./files/mona.png", function(err, im) {
if (err) throw err;
var width = im.width();
var height = im.height();
if (width < 1 || height < 1) throw new Error('Image has no size');
console.log('Image loaded from ./files/mona.png at '+im.width()+'x'+im.height());
var AfterResize = function(err, img){
if (err){
console.log('Error in resize:' + err);
return;
}
img.save("./tmp/resize-async-image.png");
console.log('Image saved to ./tmp/resize-async-image.png at '+img.width()+'x'+img.height());
img.release();
delete img;
};
var newwidth = width*0.95;
var newheight = height*0.95;
var Async = true;
if (Async){
// note - generates a new image
im.resize(newwidth, newheight, AfterResize);
im.release(); // test release image before resize if done
delete im;
} else {
// sync - note - modifies the input image
im.resize(newwidth, newheight);
AfterResize(null, im);
}
});