-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestWithGraphicsMagick.mjs
47 lines (39 loc) · 1.55 KB
/
TestWithGraphicsMagick.mjs
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
import Debug from 'debug';
import gm from './GraphicsMagic.mjs';
const debug = Debug('App:TestWithGraphicsMagick');
export default async function TestWithGraphicsMagick({ imageStream, fileName }) {
return new Promise((resolve, reject) => {
debug(`Starting ${fileName}`);
const started = process.hrtime();
const imageTransformer = gm(imageStream, fileName);
imageTransformer.profile();
imageTransformer.identify((error, value) => {
if (error) {
console.log(error);
reject(error);
return;
}
console.log(value);
const iccProfile = value.Profiles && value.Profiles['Profile-icc'];
if (iccProfile) {
debug(`[iccProfile] length ${iccProfile.length}`);
}
const deviceMake = value.Properties['exif:Make'];
const deviceModel = value.Properties['exif:Model'];
const result = {
library: {
metadata: value
},
width: value.size.width,
height: value.size.height,
colorProfile: iccProfile || 'No Profile',
colorSpaceName: value.Colorspace,
device: deviceMake && deviceModel ? `${value.Properties['exif:Make']} ${value.Properties['exif:Model']}` : 'Unknown',
libraryName: 'GM',
count: process.hrtime(started)
};
debug(`Finished ${fileName}`);
resolve(result);
});
});
}