forked from yourdeveloper/node-imagemagick
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
53 lines (46 loc) · 1.75 KB
/
test.js
File metadata and controls
53 lines (46 loc) · 1.75 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
var fs = require('fs'),
im = require('./imagemagick');
var path = __dirname + '/sample-images/blue-bottle-coffee.jpg';
var target_dst_path = __dirname + '/sample-images/';
var imdata = fs.readFileSync(path, 'binary');
im.identify(path, function (err, features) {
if (err) return console.error(err.stack || err);
console.log('identify(path) ->', features);
});
im.identify({data: imdata}, function (err, features) {
if (err) return console.error(err.stack || err);
console.log('identify({data:imdata}) ->', features);
});
im.readMetadata(path, function (err, metadata) {
if (err) return console.error(err.stack || err);
console.log('readMetadata(path) ->', metadata);
});
im.readMetadata({data: imdata}, function (err, metadata) {
if (err) return console.error(err.stack || err);
console.log('readMetadata({data:imdata} ->', metadata);
});
var timeStarted = new Date;
im.resize({
srcPath: path,
dstPath: 'test-resized.jpg',
width: 256
}, function (err, stdout, stderr) {
if (err) return console.error(err.stack || err);
console.log('resize(...) wrote "test-resized.jpg"');
console.log('real time taken for convert: ' + ((new Date) - timeStarted) + ' ms');
im.identify(['-format', '%b', 'test-resized.jpg'], function (err, r) {
if (err) throw err;
console.log("identify(['-format', '%b', 'test-resized.jpg']) ->", r);
})
});
timeStarted = new Date;
im.resize({
srcData: imdata,
width: 256
}, function (err, stdout, stderr) {
if (err) return console.error(err.stack || err);
console.log('real time taken for convert (with buffers): ' +
((new Date) - timeStarted) + ' ms');
fs.writeFileSync(target_dst_path+'test-resized-io.jpg', stdout, 'binary');
console.log('resize(...) wrote "test-resized.jpg" (' + stdout.length + ' Bytes)');
});