Skip to content

Commit a429738

Browse files
committed
comparation output
Signed-off-by: Juan Pablo Garcia Ripa <[email protected]>
1 parent 620d271 commit a429738

18 files changed

+38
-15
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
-24.1 KB
Loading
-5.06 KB
Loading
-38.2 KB
Loading
-45.5 KB
Loading
1.39 KB
Loading
-3.84 KB
Loading
-38.3 KB
Loading
-44.5 KB
Loading

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

+24-8
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,24 @@ import configure from "@jimp/custom";
77
const jimp = configure({ plugins: [] }, Jimp);
88

99
describe("EXIF orientation", () => {
10-
for (let orientation = 1; orientation <= 8; orientation++) {
10+
for (let orientation = 1; orientation <= 2; orientation++) {
1111
it(`is fixed when EXIF orientation is ${orientation}`, async () => {
1212
const regularImg = await imageWithOrientation(1);
1313
const orientedImg = await imageWithOrientation(orientation);
1414

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(
@@ -25,16 +33,24 @@ describe("EXIF orientation", () => {
2533
});
2634
}
2735

28-
for (let orientation = 1; orientation <= 8; orientation++) {
36+
for (let orientation = 1; orientation <= 0; orientation++) {
2937
it(`is fixed when EXIF orientation is ${orientation}`, async () => {
30-
const regularImg = await imageWithOrientation(1);
31-
const orientedImg = await imageWithOrientation(orientation);
38+
const regularImg = await imageWithOrientation2(1);
39+
const orientedImg = await imageWithOrientation2(orientation);
3240

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(

packages/jimp/webpack.config.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import webpack from "webpack";
21
import path from "path";
2+
import webpack from "webpack";
33

44
const isProd = process.env.NODE_ENV === "production";
55

@@ -16,6 +16,7 @@ export default {
1616
fallback: {
1717
path: require.resolve("path-browserify"),
1818
fs: false,
19+
util: false,
1920
},
2021
},
2122
plugins: [

0 commit comments

Comments
 (0)