Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ coverage/

# Misc.
.DS_Store

# VS Code
.vscode/
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ returns it as an `int`.
Retrieves '[Exif.Photo.PixelYDimension][exiv2-tags]' from the EXIF IFD and
returns it as an `int`.

##### `Orientation`

###### Description
Retrieves '[Exif.Photo.Orientation][exiv2-tags]' from the EXIF IFD and
returns it as an `int`. (Values from 1 to 8)


##### `DateTaken`

###### Description
Expand Down
7 changes: 7 additions & 0 deletions src/meta-data/definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ const definitions = {
tagType: 2,
ifd: 'exif',
parse: parseExifDate
},

Orientation: {
tagId: 0x0112,
tagType: 3,
ifd: '0',
parse: parseInt
}
};

Expand Down
28 changes: 28 additions & 0 deletions src/meta-data/exifValues.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';

const EXIF_ORIENTATION = {
ROTATE_0: {
value: 1
},
ROTATE_0_SYMETRIC: {
value: 2
},
ROTATE_180: {
value: 3
},
ROTATE_180_SYMETRIC: {
value: 4
},
ROTATE_270_SYMETRIC: {
value: 5
},
ROTATE_270: {
value: 6
},
ROTATE_90_SYMETRIC: {
value: 7
},
ROTATE_90: {
value: 8
}
}
24 changes: 24 additions & 0 deletions tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const path = require('path'),
moment = require('moment');

const cr2Raw = require('../');
const metaData = require('../src/meta-data');
const exifValues = require('../src/meta-data/exifValues');

test('extract preview image from _MG_4122.CR2', () => {

Expand Down Expand Up @@ -171,6 +173,28 @@ test('fetch date taken from _MG_8367.CR2', () => {
expect(result).toEqual(dateTaken.toDate());
});

test('fetch orientation taken from _MG_8367.CR2', () => {

const orientationTaken = exifValues.EXIF_ORIENTATION.ROTATE_0;
const cr2Path = path.resolve(__dirname, 'res', '_MG_8367.CR2');

const raw = cr2Raw(cr2Path);
const result = raw.fetchMeta(cr2Raw.meta.Orientation);

expect(result).toEqual(orientationTaken);
});

test('fetch orientation taken from _MG_0081.CR2', () => {

const orientationTaken = exifValues.EXIF_ORIENTATION.ROTATE_90;
const cr2Path = path.resolve(__dirname, 'res', '_MG_0081.CR2');

const raw = cr2Raw(cr2Path);
const result = raw.fetchMeta(cr2Raw.meta.Orientation);

expect(result).toEqual(orientationTaken);
});

test('extract preview image from notraw.jpg', () => {

const cr2Path = path.resolve(__dirname, 'res', 'notraw.jpg');
Expand Down
14 changes: 14 additions & 0 deletions tests/meta-data/definitions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,17 @@ test('defines DateTaken', () => {
expect(actual.tagType).toBe(tagType);
expect(actual.ifd).toBe(ifd);
});

test('defines Orientation', () => {

const tagId = 0x0112;
const tagType = 3;
const ifd = '0';

const actual = definitions.Orientation;

expect(actual).toBeDefined();
expect(actual.tagId).toBe(tagId);
expect(actual.tagType).toBe(tagType);
expect(actual.ifd).toBe(ifd);
});
17 changes: 17 additions & 0 deletions tests/meta-data/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const moment = require('moment');

const metaData = require('../../src/meta-data');
const { Orientation } = require('../../src/meta-data/definitions');

test('fetch fail, no ifd', () => {

Expand Down Expand Up @@ -207,3 +208,19 @@ test('fetch height', () => {

expect(actual).toBe(testHeight);
});

test('fetch orientation', () => {

const testOrientation = 1;
const testRaw = {
ifds: {
'0': {
0x0112: {
tagValue: 1
}
}
}
};
const actual = metaData.fetch(testRaw, metaData.definitions.Orientation);
expect(actual).toBe(testOrientation);
});
Binary file added tests/res/_MG_0081.CR2
Binary file not shown.