-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
35 lines (30 loc) · 978 Bytes
/
test.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
var Jimp = require('jimp');
// const image = sharp(
// '/Users/shakedlokits/Documents/Projects/BookOCR-toRemove/images/book_001.jpg',
// );
// image.metadata().then((metadata) => {
// image.extract({
// left: 0,
// top: 0,
// width: Math.round(metadata.width / 2),
// height: metadata.height,
// }).toFile('/tmp/image0.pg', (err) => {
// // Extract a region, resize, then extract from the resized image
// });
// });
const base = '/Users/shakedlokits/Desktop/imageTests/'
const imagePath = '/Users/shakedlokits/Documents/Projects/BookOCR-toRemove/images/book_001.jpg';
// open a file called "lenna.png"
Jimp.read(imagePath, (err, image) => {
if (err) throw err;
const height = image.bitmap.height;
const halfWidth = Math.floor(image.bitmap.width / 2);
image
.clone()
.crop(0, 0, halfWidth, height)
.write(base + 'left.jpg');
image
.clone()
.crop(halfWidth, 0, halfWidth, height)
.write(base + 'right.jpg');
});