Skip to content

Commit bf39f39

Browse files
committed
WIP comparation output
Signed-off-by: Juan Pablo Garcia Ripa <[email protected]>
1 parent bffcdfc commit bf39f39

16 files changed

+32
-10
lines changed

packages/core/src/utils/image-bitmap.js

+12-6
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ import FileType from "file-type";
33
import { throwError } from "@jimp/utils";
44
import EXIFParser from "exif-parser";
55
// modify-exif
6+
import modifyEXIF from "modify-exif";
67

78
import * as constants from "../constants";
89
import * as MIME from "./mime";
910
import promisify from "./promisify";
1011

1112
const EXIF_TAGS = {
1213
ORIENTATION: 0x0112, // decimal: 274
14+
IMAGE_WIDTH: 0x0100, // decimal: 256
15+
IMAGE_HEIGHT: 0x0101, // decimal: 257
1316
};
1417

1518
async function getMIMEFromBuffer(buffer, path) {
@@ -132,15 +135,18 @@ function transformBitmap(img, width, height, transformation) {
132135
}
133136
}
134137

138+
img.bitmap.data = modifyEXIF(data, (_data) => {
139+
console.log(_data);
140+
_data["0th"][274] = 1;
141+
_data["0th"][256] = width;
142+
_data["0th"][257] = height;
143+
return _data;
144+
});
145+
135146
img.bitmap.width = width;
136147
img.bitmap.height = height;
137148

138-
// img.bitmap.data = modifyEXIF(data, (_data) => {
139-
// _data["0th"][274] = 1;
140-
// return _data;
141-
// });
142-
143-
img.bitmap.data = data;
149+
// img.bitmap.data = data;
144150

145151
img._exif = EXIFParser.create(data).parse();
146152
}
-59 Bytes
Loading
-22.3 KB
Loading
-22.1 KB
Loading
391 Bytes
Loading
153 Bytes
Loading
-21.4 KB
Loading
-21 KB
Loading
-59 Bytes
Loading
-22.3 KB
Loading
-22.1 KB
Loading
391 Bytes
Loading
153 Bytes
Loading
-21.4 KB
Loading
-21 KB
Loading

packages/jimp/test/exif-rotation.test.js

+20-4
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,16 @@ describe("EXIF orientation", () => {
1515
orientedImg.write(
1616
getTestDir(__dirname) + `/Landscape-output-${orientation}-PR.jpg`
1717
);
18-
expect(orientedImg.getWidth()).toBe(regularImg.getWidth());
19-
expect(orientedImg.getHeight()).toBe(regularImg.getHeight());
18+
19+
if (orientation > 4) {
20+
// 5, 6, 7, 8 dimmensions are swapped
21+
expect(orientedImg.getWidth()).toBe(regularImg.getHeight());
22+
expect(orientedImg.getHeight()).toBe(regularImg.getWidth());
23+
} else {
24+
expect(orientedImg.getWidth()).toBe(regularImg.getWidth());
25+
expect(orientedImg.getHeight()).toBe(regularImg.getHeight());
26+
}
27+
2028
expect(Jimp.distance(regularImg, orientedImg)).toBeLessThan(0.07);
2129

2230
expect(getExifOrientation(orientedImg)).toBe(
@@ -33,8 +41,16 @@ describe("EXIF orientation", () => {
3341
orientedImg.write(
3442
getTestDir(__dirname) + `/Portrait-output-${orientation}-PR.jpg`
3543
);
36-
expect(orientedImg.getWidth()).toBe(regularImg.getWidth());
37-
expect(orientedImg.getHeight()).toBe(regularImg.getHeight());
44+
45+
if (orientation > 4) {
46+
// 5, 6, 7, 8 dimmensions are swapped
47+
expect(orientedImg.getWidth()).toBe(regularImg.getHeight());
48+
expect(orientedImg.getHeight()).toBe(regularImg.getWidth());
49+
} else {
50+
expect(orientedImg.getWidth()).toBe(regularImg.getWidth());
51+
expect(orientedImg.getHeight()).toBe(regularImg.getHeight());
52+
}
53+
3854
expect(Jimp.distance(regularImg, orientedImg)).toBeLessThan(0.07);
3955

4056
expect(getExifOrientation(orientedImg)).toBe(

0 commit comments

Comments
 (0)