Skip to content

Commit

Permalink
comparation output
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Pablo Garcia Ripa <[email protected]>
  • Loading branch information
Sarabadu committed Jul 26, 2023
1 parent 620d271 commit a429738
Show file tree
Hide file tree
Showing 18 changed files with 38 additions and 15 deletions.
18 changes: 12 additions & 6 deletions packages/core/src/utils/image-bitmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ import FileType from "file-type";
import { throwError } from "@jimp/utils";
import EXIFParser from "exif-parser";
// modify-exif
import modifyEXIF from "modify-exif";

import * as constants from "../constants";
import * as MIME from "./mime";
import promisify from "./promisify";

const EXIF_TAGS = {
ORIENTATION: 0x0112, // decimal: 274
IMAGE_WIDTH: 0x0100, // decimal: 256
IMAGE_HEIGHT: 0x0101, // decimal: 257
};

async function getMIMEFromBuffer(buffer, path) {
Expand Down Expand Up @@ -132,15 +135,18 @@ function transformBitmap(img, width, height, transformation) {
}
}

img.bitmap.data = modifyEXIF(data, (_data) => {
console.log(_data);
_data["0th"][274] = 1;
_data["0th"][256] = width;
_data["0th"][257] = height;
return _data;
});

img.bitmap.width = width;
img.bitmap.height = height;

// img.bitmap.data = modifyEXIF(data, (_data) => {
// _data["0th"][274] = 1;
// return _data;
// });

img.bitmap.data = data;
// img.bitmap.data = data;

img._exif = EXIFParser.create(data).parse();
}
Expand Down
Binary file modified packages/jimp/test/Landscape-output-2-PR.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/jimp/test/Landscape-output-3-PR.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/jimp/test/Landscape-output-4-PR.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/jimp/test/Landscape-output-5-PR.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/jimp/test/Landscape-output-6-PR.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/jimp/test/Landscape-output-7-PR.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/jimp/test/Landscape-output-8-PR.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/jimp/test/Portrait-output-1-PR.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/jimp/test/Portrait-output-2-PR.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/jimp/test/Portrait-output-3-PR.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/jimp/test/Portrait-output-4-PR.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/jimp/test/Portrait-output-5-PR.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/jimp/test/Portrait-output-6-PR.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/jimp/test/Portrait-output-7-PR.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/jimp/test/Portrait-output-8-PR.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 24 additions & 8 deletions packages/jimp/test/exif-rotation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,24 @@ import configure from "@jimp/custom";
const jimp = configure({ plugins: [] }, Jimp);

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

orientedImg.write(
getTestDir(__dirname) + `/Landscape-output-${orientation}-PR.jpg`
);
expect(orientedImg.getWidth()).toBe(regularImg.getWidth());
expect(orientedImg.getHeight()).toBe(regularImg.getHeight());

if (orientation > 4) {
// 5, 6, 7, 8 dimmensions are swapped
expect(orientedImg.getWidth()).toBe(regularImg.getHeight());
expect(orientedImg.getHeight()).toBe(regularImg.getWidth());
} else {
expect(orientedImg.getWidth()).toBe(regularImg.getWidth());
expect(orientedImg.getHeight()).toBe(regularImg.getHeight());
}

expect(Jimp.distance(regularImg, orientedImg)).toBeLessThan(0.07);

expect(getExifOrientation(orientedImg)).toBe(
Expand All @@ -25,16 +33,24 @@ describe("EXIF orientation", () => {
});
}

for (let orientation = 1; orientation <= 8; orientation++) {
for (let orientation = 1; orientation <= 0; orientation++) {
it(`is fixed when EXIF orientation is ${orientation}`, async () => {
const regularImg = await imageWithOrientation(1);
const orientedImg = await imageWithOrientation(orientation);
const regularImg = await imageWithOrientation2(1);
const orientedImg = await imageWithOrientation2(orientation);

orientedImg.write(
getTestDir(__dirname) + `/Portrait-output-${orientation}-PR.jpg`
);
expect(orientedImg.getWidth()).toBe(regularImg.getWidth());
expect(orientedImg.getHeight()).toBe(regularImg.getHeight());

if (orientation > 4) {
// 5, 6, 7, 8 dimmensions are swapped
expect(orientedImg.getWidth()).toBe(regularImg.getHeight());
expect(orientedImg.getHeight()).toBe(regularImg.getWidth());
} else {
expect(orientedImg.getWidth()).toBe(regularImg.getWidth());
expect(orientedImg.getHeight()).toBe(regularImg.getHeight());
}

expect(Jimp.distance(regularImg, orientedImg)).toBeLessThan(0.07);

expect(getExifOrientation(orientedImg)).toBe(
Expand Down
3 changes: 2 additions & 1 deletion packages/jimp/webpack.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import webpack from "webpack";
import path from "path";
import webpack from "webpack";

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

Expand All @@ -16,6 +16,7 @@ export default {
fallback: {
path: require.resolve("path-browserify"),
fs: false,
util: false,
},
},
plugins: [
Expand Down

0 comments on commit a429738

Please sign in to comment.