Skip to content

Commit

Permalink
Present ExposureTime, ShutterSpeedValue correctly when value is more …
Browse files Browse the repository at this point in the history
…than 1 sec

#201
  • Loading branch information
mattiasw committed Aug 2, 2022
1 parent 75825b5 commit 8f760cd
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dist/exif-reader.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/exif-reader.js.map

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion src/tag-names-exif-ifd.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ export default {
0x829a: {
'name': 'ExposureTime',
'description': (value) => {
if (value[0] >= value[1]) {
return `${Math.round(value[0] / value[1])}`;
}
if (value[0] !== 0) {
return `1/${Math.round(value[1] / value[0])}`;
}
Expand Down Expand Up @@ -105,7 +108,11 @@ export default {
0x9201: {
'name': 'ShutterSpeedValue',
'description': (value) => {
return `1/${Math.round(Math.pow(2, value[0] / value[1]))}`;
const denominator = Math.pow(2, value[0] / value[1]);
if (denominator <= 1) {
return `${Math.round(1 / denominator)}`;
}
return `1/${Math.round(denominator)}`;
}
},
0x9202: {
Expand Down
4 changes: 4 additions & 0 deletions test/unit/tag-names-exif-ifd-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ describe('tag-names-exif-ifd', () => {
it('should report correct name and description for ExposureTime', () => {
expect(TagNamesExifIfd[0x829a].name).to.equal('ExposureTime');
expect(TagNamesExifIfd[0x829a].description([4, 1000])).to.equal('1/250');
expect(TagNamesExifIfd[0x829a].description([6, 1])).to.equal('6');
expect(TagNamesExifIfd[0x829a].description([1, 1])).to.equal('1');
expect(TagNamesExifIfd[0x829a].description([0, 1000])).to.equal('0/1000');
});

Expand Down Expand Up @@ -130,6 +132,8 @@ describe('tag-names-exif-ifd', () => {
it('should have tag ShutterSpeedValue', () => {
expect(TagNamesExifIfd[0x9201].name).to.equal('ShutterSpeedValue');
expect(TagNamesExifIfd[0x9201].description([46435, 9999])).to.equal('1/25');
expect(TagNamesExifIfd[0x9201].description([-2584963, 1000000])).to.equal('6');
expect(TagNamesExifIfd[0x9201].description([0, 1])).to.equal('1');
expect(TagNamesExifIfd[0x9201].description([2000, 0])).to.equal('1/Infinity');
});

Expand Down

0 comments on commit 8f760cd

Please sign in to comment.