Skip to content

Commit

Permalink
Add setErrorByPass and resetOrientation (#2)
Browse files Browse the repository at this point in the history
* Add setErrorByPass and resetOrientation

* fix lint errors

* Revert "fix lint errors"

This reverts commit dbcb906.

* fix lint error

---------

Co-authored-by: Joachim Blaafjell Holwech <[email protected]>
  • Loading branch information
weden-wendy and holwech authored Mar 10, 2024
1 parent 891402a commit e7bbb5d
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 49 deletions.
44 changes: 34 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import * as _utils from './utils';

// Hacky? Yep, but sometimes you gotta do what you gotta do
export { Types, IExif, IExifElement } from './interfaces';
export { Types, IExif, IExifElement, ErrorCallback } from './interfaces';
export { Tags, TagValues } from './constants';
export { GPSHelper } from './helper';
export { ValueConvertError } from './exceptions';

import { Types, IExif, IExifElement } from './interfaces';
import { Types, IExif, IExifElement, ErrorCallback } from './interfaces';
import { TagValues } from './constants';

export const version = '2.0.0b';
Expand Down Expand Up @@ -104,12 +103,16 @@ export const load = (binary: string): IExif => {
let interopIfd: IExifElement = null;
let gpsIfd: IExifElement = null;
let thumbnail: string = null;
let firstIfdPointer: string = null;
const pointer = _utils.unpack(
exifReader.endianMark + 'L',
exifReader.tiftag.slice(4, 8),
)[0];
zerothIfd = exifReader.getIfd(pointer, '0th');
const firstIfdPointer = exifReader.getFirstIfdPointer(pointer, '0th');

if (pointer != null) {
zerothIfd = exifReader.getIfd(pointer, '0th');
firstIfdPointer = exifReader.getFirstIfdPointer(pointer, '0th');
}

if (zerothIfd !== null && 34665 in zerothIfd) {
const pointer = zerothIfd[34665];
Expand All @@ -123,15 +126,17 @@ export const load = (binary: string): IExif => {
const pointer = exifIfd[40965];
interopIfd = exifReader.getIfd(pointer, 'Interop');
}
if (firstIfdPointer != '\x00\x00\x00\x00') {
if (firstIfdPointer !== null && firstIfdPointer != '\x00\x00\x00\x00') {
const pointer = _utils.unpack(
exifReader.endianMark + 'L',
firstIfdPointer,
)[0];
firstIfd = exifReader.getIfd(pointer, '1st');
if (firstIfd !== null && 513 in firstIfd && 514 in firstIfd) {
const end = firstIfd[513] + firstIfd[514];
thumbnail = exifReader.tiftag.slice(firstIfd[513], end);
if (pointer !== null) {
firstIfd = exifReader.getIfd(pointer, '1st');
if (firstIfd !== null && 513 in firstIfd && 514 in firstIfd) {
const end = firstIfd[513] + firstIfd[514];
thumbnail = exifReader.tiftag.slice(firstIfd[513], end);
}
}
}

Expand Down Expand Up @@ -351,3 +356,22 @@ export const dump = (originalExifObj: IExif): string => {
firstIfdBytes
);
};

export const setErrorByPass = (
bypass: boolean,
errorCallback?: ErrorCallback,
): void => {
_utils.setErrorByPass(bypass, errorCallback);
};

export const resetOrientation = (exifObject: IExif): IExif => {
const orientationKey = TagValues.ImageIFD.Orientation;

if (exifObject['0th']) {
if (exifObject['0th'][orientationKey]) {
exifObject['0th'][orientationKey] = 1;
}
}

return exifObject;
};
2 changes: 2 additions & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,3 +378,5 @@ export interface ITagValues {
InteroperabilityIndex: number;
};
}

export type ErrorCallback = (e: string) => void;
Loading

0 comments on commit e7bbb5d

Please sign in to comment.