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 <sarabadu@gmail.com>
  • Loading branch information
Sarabadu committed Jul 26, 2023
1 parent 620d271 commit 18e33f3
Show file tree
Hide file tree
Showing 16 changed files with 32 additions and 10 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
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
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
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
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
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
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
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
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
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
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
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
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
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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 20 additions & 4 deletions packages/jimp/test/exif-rotation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,16 @@ describe("EXIF 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 @@ -33,8 +41,16 @@ describe("EXIF 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

0 comments on commit 18e33f3

Please sign in to comment.